diff --git a/src/Heimdall.Application/DTOs/SettingDto.cs b/src/Heimdall.Application/DTOs/SettingDto.cs index da06692..850281a 100644 --- a/src/Heimdall.Application/DTOs/SettingDto.cs +++ b/src/Heimdall.Application/DTOs/SettingDto.cs @@ -13,7 +13,8 @@ public sealed record AppSettingDto( [property: JsonPropertyName("category")] string Category, [property: JsonPropertyName("valueType")] string ValueType, [property: JsonPropertyName("allowedValues")] string? AllowedValues, - [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt + [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt, + [property: JsonPropertyName("agentScoped")] bool AgentScoped = true ); /// @@ -36,7 +37,8 @@ public sealed record CreateAppSettingRequest( [property: JsonPropertyName("category")] string Category = "General", [property: JsonPropertyName("description")] string? Description = null, [property: JsonPropertyName("valueType")] string ValueType = "string", - [property: JsonPropertyName("allowedValues")] string? AllowedValues = null + [property: JsonPropertyName("allowedValues")] string? AllowedValues = null, + [property: JsonPropertyName("agentScoped")] bool AgentScoped = true ); /// @@ -47,7 +49,8 @@ public sealed record UpdateAppSettingRequest( [property: JsonPropertyName("description")] string? Description = null, [property: JsonPropertyName("category")] string? Category = null, [property: JsonPropertyName("valueType")] string? ValueType = null, - [property: JsonPropertyName("allowedValues")] string? AllowedValues = null + [property: JsonPropertyName("allowedValues")] string? AllowedValues = null, + [property: JsonPropertyName("agentScoped")] bool? AgentScoped = null ); /// diff --git a/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs b/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs index 599b246..44e09ae 100644 --- a/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs +++ b/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs @@ -12,7 +12,8 @@ public record CreateAppSettingCommand( string Category = "General", string? Description = null, string ValueType = "string", - string? AllowedValues = null) : IRequest>; + string? AllowedValues = null, + bool AgentScoped = true) : IRequest>; public class CreateAppSettingCommandHandler : IRequestHandler> { @@ -28,7 +29,7 @@ public class CreateAppSettingCommandHandler : IRequestHandler.Conflict($"Setting '{key}' already exists"); - var setting = new AppSetting(key, request.Value, request.Category, request.Description); + var setting = new AppSetting(key, request.Value, request.Category, request.Description, request.AgentScoped); setting.UpdateMetadata(null, null, request.ValueType, request.AllowedValues); _db.AppSettings.Add(setting); @@ -38,5 +39,5 @@ public class CreateAppSettingCommandHandler : IRequestHandler new( - s.Id, s.Key, s.Value, s.Description, s.Category, s.ValueType, s.AllowedValues, s.UpdatedAt); + s.Id, s.Key, s.Value, s.Description, s.Category, s.ValueType, s.AllowedValues, s.UpdatedAt, s.AgentScoped); } diff --git a/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs b/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs index 797b6be..0a5a0af 100644 --- a/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs +++ b/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs @@ -12,7 +12,8 @@ public record UpdateAppSettingCommand( string? Description = null, string? Category = null, string? ValueType = null, - string? AllowedValues = null) : IRequest>; + string? AllowedValues = null, + bool? AgentScoped = null) : IRequest>; public class UpdateAppSettingCommandHandler : IRequestHandler> { @@ -27,12 +28,12 @@ public class UpdateAppSettingCommandHandler : IRequestHandler.NotFound($"Setting '{request.Key}' not found"); setting.UpdateValue(request.Value); - setting.UpdateMetadata(request.Description, request.Category, request.ValueType, request.AllowedValues); + setting.UpdateMetadata(request.Description, request.Category, request.ValueType, request.AllowedValues, request.AgentScoped); await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(Map(setting)); } private static AppSettingDto Map(AppSetting s) => new( - s.Id, s.Key, s.Value, s.Description, s.Category, s.ValueType, s.AllowedValues, s.UpdatedAt); + s.Id, s.Key, s.Value, s.Description, s.Category, s.ValueType, s.AllowedValues, s.UpdatedAt, s.AgentScoped); } diff --git a/src/Heimdall.Domain/Entities/AppSetting.cs b/src/Heimdall.Domain/Entities/AppSetting.cs index cc96b69..31c7f4f 100644 --- a/src/Heimdall.Domain/Entities/AppSetting.cs +++ b/src/Heimdall.Domain/Entities/AppSetting.cs @@ -26,18 +26,26 @@ public class AppSetting /// For select types, comma-separated allowed values. public string? AllowedValues { get; private set; } + /// + /// True when this setting is relevant for agents (exposed on the agent + /// detail page, can be overridden per-agent). Global-only settings + /// (server, UI) are hidden from agent views. + /// + public bool AgentScoped { get; private set; } + public DateTime CreatedAt { get; private set; } = DateTime.UtcNow; public DateTime UpdatedAt { get; private set; } = DateTime.UtcNow; private AppSetting() { } // EF Core - public AppSetting(string key, string value, string category = "General", string? description = null) + public AppSetting(string key, string value, string category = "General", string? description = null, bool agentScoped = true) { Key = !string.IsNullOrWhiteSpace(key) ? key.Trim().ToLowerInvariant() : throw new ArgumentException("Key is required", nameof(key)); Value = value ?? string.Empty; Category = category; Description = description; + AgentScoped = agentScoped; } public void UpdateValue(string value) @@ -46,12 +54,13 @@ public class AppSetting UpdatedAt = DateTime.UtcNow; } - public void UpdateMetadata(string? description, string? category, string? valueType, string? allowedValues) + public void UpdateMetadata(string? description, string? category, string? valueType, string? allowedValues, bool? agentScoped = null) { if (description is not null) Description = description; if (category is not null) Category = category; if (valueType is not null) ValueType = valueType; if (allowedValues is not null) AllowedValues = allowedValues; + if (agentScoped is not null) AgentScoped = agentScoped.Value; UpdatedAt = DateTime.UtcNow; } } diff --git a/src/Heimdall.Infrastructure/Migrations/20260810183459_AddAgentScopedSetting.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260810183459_AddAgentScopedSetting.Designer.cs new file mode 100644 index 0000000..5e9ccbb --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20260810183459_AddAgentScopedSetting.Designer.cs @@ -0,0 +1,1776 @@ +// +using System; +using Heimdall.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Heimdall.Infrastructure.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260810183459_AddAgentScopedSetting")] + partial class AddAgentScopedSetting + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ApiKeyHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("ApiKeyPrefix") + .HasMaxLength(8) + .IsUnicode(false) + .HasColumnType("character varying(8)"); + + b.Property("CpuCores") + .HasColumnType("integer"); + + b.Property("CpuUsagePercent") + .HasColumnType("double precision"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DiskUsagePercent") + .HasColumnType("double precision"); + + b.Property("GpuType") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("HasGpu") + .HasColumnType("boolean"); + + b.Property("Hostname") + .IsRequired() + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("character varying(255)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastHeartbeat") + .HasColumnType("timestamp with time zone"); + + b.Property("MemoryMb") + .HasColumnType("bigint"); + + b.Property("MemoryUsageBytes") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("PublicIp") + .HasMaxLength(45) + .IsUnicode(false) + .HasColumnType("character varying(45)"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UptimeSeconds") + .HasColumnType("bigint"); + + b.Property("Version") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("LastHeartbeat") + .HasFilter("\"Status\" = 'Online'"); + + b.HasIndex("SiteId"); + + b.ToTable("agents", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid") + .HasColumnName("agent_id"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)") + .HasColumnName("key"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_at"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text") + .HasColumnName("value"); + + b.HasKey("Id"); + + b.HasIndex("AgentId", "Key") + .IsUnique(); + + b.ToTable("agent_settings", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("CreatedByUserId") + .HasColumnType("uuid"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("KeyHash") + .IsRequired() + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("KeyPrefix") + .IsRequired() + .HasMaxLength(8) + .IsUnicode(false) + .HasColumnType("character varying(8)"); + + b.Property("LastUsedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("KeyHash"); + + b.HasIndex("KeyPrefix"); + + b.HasIndex("SiteId"); + + b.ToTable("api_keys", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("roles", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentScoped") + .HasColumnType("boolean"); + + b.Property("AllowedValues") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)") + .HasColumnName("allowed_values"); + + b.Property("Category") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasColumnName("category"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("character varying(500)") + .HasColumnName("description"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)") + .HasColumnName("key"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_at"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text") + .HasColumnName("value"); + + b.Property("ValueType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("value_type"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique(); + + b.ToTable("app_settings", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("Language") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(10) + .IsUnicode(false) + .HasColumnType("character varying(10)") + .HasDefaultValue("fr"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("MustChangePassword") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("Theme") + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)") + .HasDefaultValue("Auto"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Action") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("IpAddress") + .HasMaxLength(45) + .IsUnicode(false) + .HasColumnType("character varying(45)"); + + b.Property("NewValue") + .HasColumnType("text"); + + b.Property("OldValue") + .HasColumnType("text"); + + b.Property("ResourceId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("ResourceType") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Timestamp") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("Timestamp") + .IsDescending(); + + b.HasIndex("UserId"); + + b.HasIndex("ResourceType", "ResourceId", "Timestamp") + .IsDescending(false, false, true); + + b.ToTable("audit_logs", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("Capabilities") + .IsRequired() + .HasMaxLength(64) + .IsUnicode(false) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DetectedType") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("DiscoveryMethod") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("HasAudio") + .HasColumnType("boolean"); + + b.Property("HasMotionDetection") + .HasColumnType("boolean"); + + b.Property("HasPtz") + .HasColumnType("boolean"); + + b.Property("HttpPort") + .HasColumnType("integer"); + + b.Property("IpAddress") + .HasMaxLength(45) + .HasColumnType("character varying(45)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastDiscoveredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastStreamTestAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastTestedCodecs") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("LastTestedHeight") + .HasColumnType("integer"); + + b.Property("LastTestedLatencyMs") + .HasColumnType("bigint"); + + b.Property("LastTestedWidth") + .HasColumnType("integer"); + + b.Property("MacAddress") + .HasMaxLength(17) + .HasColumnType("character varying(17)"); + + b.Property("Manufacturer") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Model") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("OnvifPort") + .HasColumnType("integer"); + + b.Property("RtspPort") + .HasColumnType("integer"); + + b.Property("RtspUrl") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("character varying(1000)"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("SubRtspUrl") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("character varying(1000)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("AgentId"); + + b.HasIndex("IpAddress"); + + b.HasIndex("MacAddress"); + + b.HasIndex("SiteId"); + + b.ToTable("cameras", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("Reason") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("ReleasedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AssignedAt"); + + b.HasIndex("AgentId", "ReleasedAt") + .HasFilter("\"ReleasedAt\" IS NULL"); + + b.HasIndex("CameraId", "ReleasedAt") + .IsUnique() + .HasFilter("\"ReleasedAt\" IS NULL"); + + b.ToTable("camera_assignments", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => + { + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("OnvifPassword") + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("character varying(500)"); + + b.Property("OnvifUsername") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)") + .HasDefaultValue("admin"); + + b.Property("RtspPassword") + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("character varying(500)"); + + b.Property("RtspUsername") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("CameraId"); + + b.ToTable("camera_credentials", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => + { + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("ActiveIntervalMs") + .HasColumnType("integer"); + + b.Property("AnimalCooldownSec") + .HasColumnType("integer"); + + b.Property("DetectAnimal") + .HasColumnType("boolean"); + + b.Property("DetectMotion") + .HasColumnType("boolean"); + + b.Property("DetectPackage") + .HasColumnType("boolean"); + + b.Property("DetectPerson") + .HasColumnType("boolean"); + + b.Property("DetectVehicle") + .HasColumnType("boolean"); + + b.Property("FaceRecognition") + .HasColumnType("boolean"); + + b.Property("IdleIntervalMs") + .HasColumnType("integer"); + + b.Property("IoUThreshold") + .HasColumnType("double precision"); + + b.Property("LicensePlateRecognition") + .HasColumnType("boolean"); + + b.Property("MaxEventsPerMinute") + .HasColumnType("integer"); + + b.Property("MinConfidence") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.40000000000000002); + + b.Property("MotionIntervalMs") + .HasColumnType("integer"); + + b.Property("MotionThreshold") + .HasColumnType("double precision"); + + b.Property("PersonCooldownSec") + .HasColumnType("integer"); + + b.Property("RequireMotionForAI") + .HasColumnType("boolean"); + + b.Property("VehicleCooldownSec") + .HasColumnType("integer"); + + b.Property("YoloModel") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)") + .HasDefaultValue("yolov8n"); + + b.HasKey("CameraId"); + + b.ToTable("camera_detection_profiles", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DetectedType") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("DiscoveryMethod") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("HomeKitDeviceId") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("HomeKitModel") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("HomeKitName") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("Hostname") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("character varying(255)"); + + b.Property("HttpPort") + .HasColumnType("integer"); + + b.Property("HttpServerHeader") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("HttpStatusCode") + .HasColumnType("integer"); + + b.Property("IpAddress") + .IsRequired() + .HasMaxLength(45) + .IsUnicode(false) + .HasColumnType("character varying(45)"); + + b.Property("IsHomeKitCamera") + .HasColumnType("boolean"); + + b.Property("IsProcessed") + .HasColumnType("boolean"); + + b.Property("IsReachable") + .HasColumnType("boolean"); + + b.Property("MacAddress") + .HasMaxLength(17) + .IsUnicode(false) + .HasColumnType("character varying(17)"); + + b.Property("OnvifDeviceServiceUrl") + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("character varying(500)"); + + b.Property("OnvifHardware") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("OnvifName") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("OnvifPort") + .HasColumnType("integer"); + + b.PrimitiveCollection("OpenPorts") + .IsRequired() + .IsUnicode(false) + .HasColumnType("integer[]"); + + b.Property("ProbedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Vendor") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.HasIndex("IpAddress"); + + b.HasIndex("IsProcessed"); + + b.HasIndex("SiteId"); + + b.ToTable("camera_discovery_results", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("Confidence") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.0); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("Label") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("MetadataJson") + .HasColumnType("jsonb"); + + b.Property("OccurredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SnapshotThumbUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("SnapshotUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("OccurredAt"); + + b.HasIndex("CameraId", "OccurredAt") + .IsDescending(false, true); + + b.HasIndex("CameraId", "Type"); + + b.ToTable("camera_events", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.PrimitiveCollection("Codecs") + .IsRequired() + .IsUnicode(false) + .HasColumnType("text[]"); + + b.Property("DiscoveryResultId") + .HasColumnType("uuid"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("IsAlive") + .HasColumnType("boolean"); + + b.Property("IsMainStream") + .HasColumnType("boolean"); + + b.Property("LatencyMs") + .HasColumnType("bigint"); + + b.Property("Protocol") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Url") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DiscoveryResultId"); + + b.HasIndex("IsAlive"); + + b.HasIndex("IsMainStream"); + + b.ToTable("discovered_streams", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted") + .HasFilter("\"IsDeleted\" = false"); + + b.HasIndex("Name"); + + b.ToTable("groups", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Embedding") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.Property("SourceEventId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("ThumbnailUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("PersonId"); + + b.ToTable("known_faces", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("EventType") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("IsRead") + .HasColumnType("boolean"); + + b.Property("Link") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("ReadAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("SnapshotUrl") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAt"); + + b.HasIndex("UserId"); + + b.HasIndex("UserId", "IsRead"); + + b.ToTable("notifications", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.NotificationTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BodyMarkdown") + .IsRequired() + .HasColumnType("text"); + + b.Property("Channel") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("EventType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("IsDefault") + .HasColumnType("boolean"); + + b.Property("Language") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(10) + .HasColumnType("character varying(10)") + .HasDefaultValue("fr"); + + b.Property("Subject") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("EventType", "Channel", "Language") + .IsUnique(); + + b.ToTable("notification_templates", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsWatchlisted") + .HasColumnType("boolean"); + + b.Property("Notes") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("PhotoUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Category"); + + b.HasIndex("DisplayName"); + + b.HasIndex("IsWatchlisted"); + + b.ToTable("persons", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.RevokedRefreshToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RevokedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("TokenHash") + .IsRequired() + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ExpiresAt"); + + b.HasIndex("TokenHash") + .IsUnique(); + + b.ToTable("revoked_refresh_tokens", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("RegistrationTokenHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("Timezone") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)") + .HasDefaultValue("UTC"); + + b.Property("TokenExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted") + .HasFilter("\"IsDeleted\" = false"); + + b.HasIndex("Name"); + + b.ToTable("sites", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("GroupId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "GroupId"); + + b.HasIndex("GroupId"); + + b.ToTable("user_groups", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserNotificationConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DailyDigest") + .HasColumnType("boolean"); + + b.Property("EmailAddress") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("EmailEnabled") + .HasColumnType("boolean"); + + b.Property("Language") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(10) + .HasColumnType("character varying(10)") + .HasDefaultValue("fr"); + + b.Property("NtfyEnabled") + .HasColumnType("boolean"); + + b.Property("NtfyUrl") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("SubscribedEventsJson") + .HasColumnType("jsonb") + .HasColumnName("subscribed_events"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("WeeklyDigest") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("user_notification_configs", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "SiteId"); + + b.HasIndex("SiteId"); + + b.ToTable("user_sites", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("role_claims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_claims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("user_logins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("user_roles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("user_tokens", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany("Agents") + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany() + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Agent"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany() + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany("Cameras") + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany("Cameras") + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Agent"); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany() + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Agent"); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithOne("Credentials") + .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithOne("DetectionProfile") + .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany() + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => + { + b.HasOne("Heimdall.Domain.Entities.CameraDiscoveryResult", "DiscoveryResult") + .WithMany("DiscoveredStreams") + .HasForeignKey("DiscoveryResultId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DiscoveryResult"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany("Faces") + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Person"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => + { + b.HasOne("Heimdall.Domain.Entities.Group", "Group") + .WithMany("UserGroups") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.AppUser", "User") + .WithMany("UserGroups") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany() + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.AppUser", "User") + .WithMany("UserSites") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Site"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Heimdall.Domain.Entities.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Heimdall.Domain.Entities.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => + { + b.Navigation("Cameras"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => + { + b.Navigation("UserGroups"); + + b.Navigation("UserSites"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => + { + b.Navigation("Credentials"); + + b.Navigation("DetectionProfile"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => + { + b.Navigation("DiscoveredStreams"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => + { + b.Navigation("UserGroups"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Person", b => + { + b.Navigation("Faces"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => + { + b.Navigation("Agents"); + + b.Navigation("Cameras"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/20260810183459_AddAgentScopedSetting.cs b/src/Heimdall.Infrastructure/Migrations/20260810183459_AddAgentScopedSetting.cs new file mode 100644 index 0000000..a10a67f --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20260810183459_AddAgentScopedSetting.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Heimdall.Infrastructure.Migrations +{ + /// + public partial class AddAgentScopedSetting : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "AgentScoped", + table: "app_settings", + type: "boolean", + nullable: false, + defaultValue: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AgentScoped", + table: "app_settings"); + } + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs index d448b38..2cd2845 100644 --- a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs +++ b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs @@ -245,6 +245,9 @@ namespace Heimdall.Infrastructure.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); + b.Property("AgentScoped") + .HasColumnType("boolean"); + b.Property("AllowedValues") .HasMaxLength(2000) .HasColumnType("character varying(2000)") diff --git a/src/Heimdall.Web/Components/Pages/AgentDetail.razor b/src/Heimdall.Web/Components/Pages/AgentDetail.razor index a7b155f..279648b 100644 --- a/src/Heimdall.Web/Components/Pages/AgentDetail.razor +++ b/src/Heimdall.Web/Components/Pages/AgentDetail.razor @@ -99,11 +99,11 @@ else - @* ─── Agent Settings Overrides ─── *@ - + HelpText="Paramètres globaux hérités par cet agent, modifiables pour ce site uniquement. Envoyés en temps réel via SignalR."> @if (_settingsLoading) { @@ -116,48 +116,116 @@ else Réessayer } - else if (_settings.Count == 0) + else if (_globalSettings.Count == 0 && _settings.Count == 0) { - Aucune configuration spécifique pour cet agent. - Ajoutez un réglage pour surcharger la configuration globale. + Aucun paramètre global exposé aux agents pour le moment. } else { - - - - - - - - Clé - Valeur - Actions - - - @context.Key - @context.Value - - - - - - - - - - + @foreach (var category in _globalSettings.GroupBy(s => s.Category).OrderBy(g => g.Key)) + { +
+
+ + + @category.Key + + @category.Count() +
+ + + @foreach (var setting in category) + { + var overridden = IsOverridden(setting.Key); + var effectiveValue = EffectiveValue(setting.Key, setting.Value); + + +
+ +
+ + @(setting.Description ?? HumanizeAgentKey(setting.Key)) + + + @setting.Key + +
+ @if (overridden) + { + + + + } +
+ + @if (overridden) + { + + Surchargé pour cet agent + + } + else + { + + Hérité (global) + + } + + @switch (setting.ValueType.ToLowerInvariant()) + { + case "boolean": + case "bool": +
+ + + @(effectiveValue?.Equals("true", StringComparison.OrdinalIgnoreCase) == true ? "Activé" : "Désactivé") + +
+ break; + case "number": + case "int": + case "integer": + case "double": + + break; + case "select": + case "dropdown": + + @foreach (var opt in (setting.AllowedValues ?? "").Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + { + @opt + } + + break; + default: + + break; + } +
+
+ } +
+
+ } } - - - Ajouter un réglage - + @if (_settings.Count > 0) + { + + @_settings.Count réglage(s) surchargé(s) pour cet agent — la valeur globale est ignorée pour ces clés. + + }
@@ -237,6 +305,7 @@ else // Settings private List _settings = []; + private List _globalSettings = []; private bool _settingsLoading; private bool _settingsError; private bool _saving; @@ -272,16 +341,54 @@ else _settingsLoading = true; try { + _globalSettings = (await Api.GetSettingsAsync()) + .Where(s => s.AgentScoped) + .OrderBy(s => s.Category) + .ThenBy(s => s.Key) + .ToList(); _settings = await Api.GetAgentSettingsAsync(Id); } catch { _settingsError = true; _settings = []; + _globalSettings = []; } finally { _settingsLoading = false; } } + /// Returns the effective value for a global setting key (override wins). + private string EffectiveValue(string key, string globalValue) + => _settings.FirstOrDefault(s => s.Key == key)?.Value ?? globalValue; + + /// True when the agent overrides this global key. + private bool IsOverridden(string key) + => _settings.Any(s => s.Key == key); + + private async Task SaveGlobalOverrideAsync(AppSettingItem setting, string value) + { + _saving = true; + try + { + var response = await Api.SetAgentSettingAsync(Id, new SetAgentSettingRequest(setting.Key, value)); + if (response.IsSuccessStatusCode) + { + Snackbar.Add($"« {setting.Key} » surchargé pour cet agent — envoyé en temps réel", Severity.Success); + await LoadSettingsAsync(); + } + else + { + var error = await response.Content.ReadAsStringAsync(); + Snackbar.Add($"Erreur : {error}", Severity.Error); + } + } + catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); } + finally { _saving = false; } + } + + private async Task SaveGlobalOverrideBoolAsync(AppSettingItem setting, bool value) + => await SaveGlobalOverrideAsync(setting, value.ToString().ToLowerInvariant()); + private void OpenAddDialog() { _editingSetting = null; @@ -351,6 +458,26 @@ else finally { _deleting = false; } } + private async Task ExecuteRemoveSettingByKey(string key) + { + _deleting = true; + try + { + var response = await Api.RemoveAgentSettingAsync(Id, key); + if (response.IsSuccessStatusCode) + { + Snackbar.Add($"« {key} » réinitialisé à la valeur globale — agent notifié", Severity.Success); + await LoadSettingsAsync(); + } + else + { + Snackbar.Add("Erreur lors de la réinitialisation", Severity.Error); + } + } + catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); } + finally { _deleting = false; } + } + public void Dispose() { // No unmanaged resources to dispose @@ -378,4 +505,42 @@ else > 0 => $"{mb} Mo", _ => "-" }; + + // ─── Settings visual helpers ───────────────────────────────────── + + private static Color GetAgentTypeColor(string valueType) => valueType.ToLowerInvariant() switch + { + "boolean" or "bool" => Color.Success, + "number" or "int" or "integer" or "double" => Color.Info, + "select" or "dropdown" => Color.Warning, + _ => Color.Secondary + }; + + private static string GetAgentTypeIcon(string valueType) => valueType.ToLowerInvariant() switch + { + "boolean" or "bool" => Icons.Material.Filled.ToggleOn, + "number" or "int" or "integer" or "double" => Icons.Material.Filled.Tag, + "select" or "dropdown" => Icons.Material.Filled.ArrowDropDownCircle, + _ => Icons.Material.Filled.TextFields + }; + + private static string GetAgentCategoryIcon(string category) => category.ToLowerInvariant() switch + { + "detection" => Icons.Material.Filled.Visibility, + "recording" => Icons.Material.Filled.Videocam, + "logging" or "log" => Icons.Material.Filled.BugReport, + "network" => Icons.Material.Filled.Wifi, + "storage" => Icons.Material.Filled.Storage, + "notification" or "notifications" => Icons.Material.Filled.Notifications, + "heartbeat" => Icons.Material.Filled.MonitorHeart, + _ => Icons.Material.Filled.Settings + }; + + private static string HumanizeAgentKey(string key) + { + var parts = key.Split('.', '_', '-'); + return string.Join(' ', parts.Select(p => p.Length <= 2 + ? p.ToUpperInvariant() + : char.ToUpperInvariant(p[0]) + p[1..])); + } } diff --git a/src/Heimdall.Web/Components/Pages/SettingsPage.razor b/src/Heimdall.Web/Components/Pages/SettingsPage.razor index d133243..3b44330 100644 --- a/src/Heimdall.Web/Components/Pages/SettingsPage.razor +++ b/src/Heimdall.Web/Components/Pages/SettingsPage.razor @@ -205,6 +205,10 @@ else HelperText="Ex: valeur1,valeur2,valeur3" /> } + + @if (!string.IsNullOrEmpty(_createError)) { @_createError @@ -371,6 +375,7 @@ else private string _createCategory = "General"; private string _createValueType = "string"; private string _createAllowedValues = ""; + private bool _createAgentScoped = true; private string _createError = ""; // Delete state @@ -503,7 +508,8 @@ else string.IsNullOrWhiteSpace(_createCategory) ? "General" : _createCategory.Trim(), string.IsNullOrWhiteSpace(_createDescription) ? null : _createDescription.Trim(), _createValueType, - allowedValues + allowedValues, + _createAgentScoped )); if (!result.IsSuccessStatusCode) diff --git a/src/Heimdall.Web/Services/HeimdallApiClient.cs b/src/Heimdall.Web/Services/HeimdallApiClient.cs index 6bd4bf4..2b8c457 100644 --- a/src/Heimdall.Web/Services/HeimdallApiClient.cs +++ b/src/Heimdall.Web/Services/HeimdallApiClient.cs @@ -548,7 +548,8 @@ public record AppSettingItem( [property: JsonPropertyName("category")] string Category, [property: JsonPropertyName("valueType")] string ValueType, [property: JsonPropertyName("allowedValues")] string? AllowedValues, - [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt + [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt, + [property: JsonPropertyName("agentScoped")] bool AgentScoped = true ); public record CreateAppSettingRequest( @@ -557,7 +558,8 @@ public record CreateAppSettingRequest( [property: JsonPropertyName("category")] string Category = "General", [property: JsonPropertyName("description")] string? Description = null, [property: JsonPropertyName("valueType")] string ValueType = "string", - [property: JsonPropertyName("allowedValues")] string? AllowedValues = null + [property: JsonPropertyName("allowedValues")] string? AllowedValues = null, + [property: JsonPropertyName("agentScoped")] bool AgentScoped = true ); public record UpdateAppSettingRequest( @@ -565,7 +567,8 @@ public record UpdateAppSettingRequest( [property: JsonPropertyName("description")] string? Description = null, [property: JsonPropertyName("category")] string? Category = null, [property: JsonPropertyName("valueType")] string? ValueType = null, - [property: JsonPropertyName("allowedValues")] string? AllowedValues = null + [property: JsonPropertyName("allowedValues")] string? AllowedValues = null, + [property: JsonPropertyName("agentScoped")] bool? AgentScoped = null ); // ─── Agent Settings DTOs ─────────────────────────────────────────── diff --git a/tests/Heimdall.Application.Tests/Validators/CreateAppSettingValidatorTests.cs b/tests/Heimdall.Application.Tests/Validators/CreateAppSettingValidatorTests.cs index 1658739..57ffc22 100644 --- a/tests/Heimdall.Application.Tests/Validators/CreateAppSettingValidatorTests.cs +++ b/tests/Heimdall.Application.Tests/Validators/CreateAppSettingValidatorTests.cs @@ -86,4 +86,32 @@ public class CreateAppSettingValidatorTests var result = _sut.TestValidate(request); result.IsValid.ShouldBeTrue(); } + + [Theory] + [InlineData("boolean")] + [InlineData("number")] + [InlineData("integer")] + [InlineData("dropdown")] + public void AliasValueTypes_PassesValidation(string valueType) + { + var request = new CreateAppSettingRequest( + Key: "test.alias", + Value: "value", + Category: "General", + ValueType: valueType); + + var result = _sut.TestValidate(request); + result.IsValid.ShouldBeTrue(); + } + + [Fact] + public void AgentScoped_Default_IsTrue() + { + var request = new CreateAppSettingRequest( + Key: "test.agentscoped", + Value: "value", + Category: "General"); + + request.AgentScoped.ShouldBeTrue(); + } } diff --git a/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs new file mode 100644 index 0000000..1f6e6b7 --- /dev/null +++ b/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs @@ -0,0 +1,125 @@ +using Bunit; +using System.Net.Http.Json; +using System.Text.Json; +using Heimdall.Web.Components.Pages; +using Heimdall.Web.Services; +using Microsoft.Extensions.DependencyInjection; +using MudBlazor; +using Shouldly; + +namespace Heimdall.Web.Tests.Components.Pages; + +public class AgentDetailTests : PageTestBase +{ + private static readonly Guid AgentId = Guid.NewGuid(); + + private static AgentItem Agent() => new() + { + Id = AgentId, + SiteId = Guid.NewGuid(), + SiteName = "Site Principal", + Name = "agent-01", + Hostname = "agent-01", + Version = "1.0.0", + Status = "Online", + LastHeartbeat = DateTime.UtcNow, + PublicIp = "10.0.0.5", + CreatedAt = DateTime.UtcNow.AddDays(-5) + }; + + private static AppSettingItem Setting(string key, string value, string category, string valueType, bool agentScoped = true, string? description = null) => new( + Guid.NewGuid(), key, value, description, category, valueType, null, DateTime.UtcNow, agentScoped); + + private static AgentSettingItem Override(string key, string value) => new( + Guid.NewGuid(), AgentId, key, value, DateTime.UtcNow); + + [Fact] + public void AgentDetail_AfficheGlobauxHerites_AvecBadge() + { + // Ordre important : les routes spécifiques /settings AVANT api/agents/{id} + // (RoutedHandler matche par Contains) + Handler.OnGet($"api/settings/agent/{AgentId}/overrides", new List()); + Handler.OnGet("api/settings", new List + { + Setting("detection.threshold", "0.7", "Detection", "number", true, "Seuil de détection"), + Setting("recording.enabled", "true", "Recording", "boolean", true, "Enregistrement activé"), + Setting("server.internal.port", "8080", "Server", "number", false, "Port interne (non agent)") + }); + Handler.OnGet($"api/agents/{AgentId}", Agent()); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, AgentId)); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("agent-01")); + + // Les globaux agent-scoped sont affichés avec leurs libellés + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("Seuil de détection"); + cut.Markup.ShouldContain("Enregistrement activé"); + cut.Markup.ShouldContain("Hérité (global)"); + }); + + // Le setting non agent-scoped n'apparaît pas + cut.Markup.ShouldNotContain("server.internal.port"); + } + + [Fact] + public void AgentDetail_ModifierGlobal_CreeSurcharge() + { + Handler.OnGet($"api/settings/agent/{AgentId}/overrides", new List()); + Handler.On(HttpMethod.Put, $"api/settings/agent/{AgentId}/overrides", System.Net.HttpStatusCode.OK); + Handler.OnGet("api/settings", new List + { + Setting("detection.threshold", "0.7", "Detection", "number", true, "Seuil de détection") + }); + Handler.OnGet($"api/agents/{AgentId}", Agent()); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, AgentId)); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("Seuil de détection")); + + // Modifier la valeur dans la carte → crée un override + cut.FindAll(".settings-card .mud-input input")[0].Change("0.9"); + cut.WaitForAssertion(() => + Handler.Requests.Any(r => r.Method == HttpMethod.Put + && r.RequestUri!.AbsolutePath.Contains($"api/settings/agent/{AgentId}/overrides")).ShouldBeTrue()); + + var put = Handler.Requests.First(r => r.Method == HttpMethod.Put + && r.RequestUri!.AbsolutePath.Contains($"api/settings/agent/{AgentId}/overrides")); + put.RequestUri!.AbsolutePath.ShouldContain(AgentId.ToString()); + } + + [Fact] + public void AgentDetail_SurchargeExistante_AfficheBadgeEtReinitialise() + { + Handler.OnGet($"api/settings/agent/{AgentId}/overrides", new List + { + Override("detection.threshold", "0.9") + }); + Handler.On(HttpMethod.Delete, $"api/settings/agent/{AgentId}/overrides", System.Net.HttpStatusCode.OK); + Handler.OnGet("api/settings", new List + { + Setting("detection.threshold", "0.7", "Detection", "number", true, "Seuil de détection") + }); + Handler.OnGet($"api/agents/{AgentId}", Agent()); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, AgentId)); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("Seuil de détection")); + + // La carte affiche la valeur surchargée et le badge + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("Surchargé pour cet agent"); + cut.Markup.ShouldContain("0.9"); + }); + + // Le bouton Restore (réinitialiser) déclenche le DELETE + cut.FindAll("button.mud-icon-button").First(b => + b.QuerySelector("svg") is not null).Click(); + + cut.WaitForAssertion(() => + Handler.Requests.Any(r => r.Method == HttpMethod.Delete + && r.RequestUri!.AbsolutePath.Contains($"api/settings/agent/{AgentId}/overrides")).ShouldBeTrue()); + } +}