diff --git a/src/Heimdall.Application/Common/IApplicationDbContext.cs b/src/Heimdall.Application/Common/IApplicationDbContext.cs index 9a9bca3..da1a99c 100644 --- a/src/Heimdall.Application/Common/IApplicationDbContext.cs +++ b/src/Heimdall.Application/Common/IApplicationDbContext.cs @@ -26,13 +26,17 @@ public interface IApplicationDbContext DbSet UserNotificationConfigs { get; } DbSet Groups { get; } DbSet KnownFaces { get; } + DbSet LicensePlates { get; } DbSet Persons { get; } + DbSet Recordings { get; } DbSet RevokedRefreshTokens { get; } DbSet Sites { get; } DbSet SiteCredentials { get; } + DbSet StoragePolicies { get; } DbSet UserGroups { get; } DbSet UserRecoveryCodes { get; } DbSet UserSites { get; } + DbSet Vehicles { get; } Task SaveChangesAsync(CancellationToken cancellationToken); Task SaveChangesWithRetryAsync(int maxRetries = 3, CancellationToken ct = default); } diff --git a/src/Heimdall.Domain/Entities/Camera.cs b/src/Heimdall.Domain/Entities/Camera.cs index 8258e24..ffe5d86 100644 --- a/src/Heimdall.Domain/Entities/Camera.cs +++ b/src/Heimdall.Domain/Entities/Camera.cs @@ -72,6 +72,12 @@ public class Camera : Entity, IAuditableEntity, ISoftDeletable public CameraCredentials? Credentials { get; private set; } public CameraDetectionProfile? DetectionProfile { get; private set; } + /// Storage policy applied to this camera's recordings (N:1). + public Guid? StoragePolicyId { get; private set; } + public StoragePolicy? StoragePolicy { get; private set; } + + public void AssignStoragePolicy(Guid storagePolicyId) => StoragePolicyId = storagePolicyId; + private Camera() { } // EF Core public Camera( diff --git a/src/Heimdall.Domain/Entities/CameraEvent.cs b/src/Heimdall.Domain/Entities/CameraEvent.cs index 78be47c..fcff42a 100644 --- a/src/Heimdall.Domain/Entities/CameraEvent.cs +++ b/src/Heimdall.Domain/Entities/CameraEvent.cs @@ -19,12 +19,35 @@ public class CameraEvent : Entity, IAuditableEntity public string? MetadataJson { get; private set; } // JSON: bounding boxes, track ID, etc. public DateTime OccurredAt { get; private set; } + // ── Relations métier (spec 2.1/2.2) ───────────────────────────── + /// Vehicle linked to this event (Event → Vehicle N:1). + public Guid? VehicleId { get; private set; } + + /// Recording segment linked to this event (Event → Recording N:1). + public Guid? RecordingId { get; private set; } + + /// Parent event for event hierarchies (Event → Event N:1). + public Guid? ParentEventId { get; private set; } + + // ── Déduplication (spec 2.1) ──────────────────────────────────── + /// Stable hash of detection content used for deduplication. + public string? DetectionHash { get; private set; } + + /// True when the event was suppressed (duplicate / low value). + public bool IsSuppressed { get; private set; } + + /// Tracking identifier grouping frames of the same object. + public string? TrackId { get; private set; } + // Audit public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } // Navigation public Camera Camera { get; private set; } = null!; + public Vehicle? Vehicle { get; private set; } + public Recording? Recording { get; private set; } + public CameraEvent? ParentEvent { get; private set; } private CameraEvent() { } // EF Core @@ -51,4 +74,11 @@ public class CameraEvent : Entity, IAuditableEntity } public void AssignAgent(Guid agentId) => AgentId = agentId; + + public void AssignVehicle(Guid vehicleId) => VehicleId = vehicleId; + public void AssignRecording(Guid recordingId) => RecordingId = recordingId; + public void AssignParentEvent(Guid parentEventId) => ParentEventId = parentEventId; + public void SetTrackId(string trackId) => TrackId = trackId; + public void SetDetectionHash(string detectionHash) => DetectionHash = detectionHash; + public void SetSuppressed(bool suppressed) => IsSuppressed = suppressed; } diff --git a/src/Heimdall.Domain/Entities/LicensePlate.cs b/src/Heimdall.Domain/Entities/LicensePlate.cs new file mode 100644 index 0000000..064305a --- /dev/null +++ b/src/Heimdall.Domain/Entities/LicensePlate.cs @@ -0,0 +1,36 @@ +using Heimdall.Domain.Primitives; + +namespace Heimdall.Domain.Entities; + +/// +/// A license plate observation (OCR result). +/// Linked to a vehicle and optionally to a person (driver/owner). +/// +public class LicensePlate : Entity, IAuditableEntity +{ + public string PlateText { get; private set; } = string.Empty; + public Guid? VehicleId { get; private set; } + public Guid? PersonId { get; private set; } + public double Confidence { get; private set; } + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } + + // Navigation + public Vehicle? Vehicle { get; private set; } + public Person? Person { get; private set; } + + private LicensePlate() { } // EF Core + + public LicensePlate(string plateText, Guid? vehicleId = null, Guid? personId = null, double confidence = 0) + : base(Guid.NewGuid()) + { + PlateText = plateText; + VehicleId = vehicleId; + PersonId = personId; + Confidence = confidence; + } + + public void AssignVehicle(Guid vehicleId) => VehicleId = vehicleId; + public void AssignPerson(Guid personId) => PersonId = personId; + public void UpdateConfidence(double confidence) => Confidence = confidence; +} diff --git a/src/Heimdall.Domain/Entities/Recording.cs b/src/Heimdall.Domain/Entities/Recording.cs new file mode 100644 index 0000000..332e341 --- /dev/null +++ b/src/Heimdall.Domain/Entities/Recording.cs @@ -0,0 +1,48 @@ +using Heimdall.Domain.Enums; +using Heimdall.Domain.Primitives; + +namespace Heimdall.Domain.Entities; + +/// +/// A recorded video segment from a camera, stored on a storage provider (S3 or local). +/// Linked to a storage policy that defines retention. +/// +public class Recording : Entity, IAuditableEntity +{ + public Guid CameraId { get; private set; } + public DateTime Timestamp { get; private set; } + public double DurationSeconds { get; private set; } + public string StoragePath { get; private set; } = string.Empty; + public long SizeBytes { get; private set; } + public StorageProvider StorageProvider { get; private set; } = StorageProvider.S3; + public Guid? StoragePolicyId { get; private set; } + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } + + // Navigation + public Camera Camera { get; private set; } = null!; + public StoragePolicy? StoragePolicy { get; private set; } + + private Recording() { } // EF Core + + public Recording( + Guid cameraId, + DateTime timestamp, + double durationSeconds, + string storagePath, + long sizeBytes, + StorageProvider storageProvider, + Guid? storagePolicyId = null) + : base(Guid.NewGuid()) + { + CameraId = cameraId; + Timestamp = timestamp; + DurationSeconds = durationSeconds; + StoragePath = storagePath; + SizeBytes = sizeBytes; + StorageProvider = storageProvider; + StoragePolicyId = storagePolicyId; + } + + public void AssignStoragePolicy(Guid storagePolicyId) => StoragePolicyId = storagePolicyId; +} diff --git a/src/Heimdall.Domain/Entities/StoragePolicy.cs b/src/Heimdall.Domain/Entities/StoragePolicy.cs new file mode 100644 index 0000000..31d0758 --- /dev/null +++ b/src/Heimdall.Domain/Entities/StoragePolicy.cs @@ -0,0 +1,34 @@ +using Heimdall.Domain.Enums; +using Heimdall.Domain.Primitives; + +namespace Heimdall.Domain.Entities; + +/// +/// Retention and storage policy for camera recordings. +/// Multiple cameras can share the same policy (N:1). +/// +public class StoragePolicy : Entity, IAuditableEntity +{ + public string Name { get; private set; } = string.Empty; + public int RetentionDays { get; private set; } = 30; + public StorageProvider StorageProvider { get; private set; } = StorageProvider.S3; + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } + + private StoragePolicy() { } // EF Core + + public StoragePolicy(string name, int retentionDays, StorageProvider storageProvider) + : base(Guid.NewGuid()) + { + Name = name; + RetentionDays = retentionDays; + StorageProvider = storageProvider; + } + + public void Update(string name, int retentionDays, StorageProvider storageProvider) + { + Name = name; + RetentionDays = retentionDays; + StorageProvider = storageProvider; + } +} diff --git a/src/Heimdall.Domain/Entities/Vehicle.cs b/src/Heimdall.Domain/Entities/Vehicle.cs new file mode 100644 index 0000000..0a42ff6 --- /dev/null +++ b/src/Heimdall.Domain/Entities/Vehicle.cs @@ -0,0 +1,43 @@ +using Heimdall.Domain.Primitives; + +namespace Heimdall.Domain.Entities; + +/// +/// A vehicle of interest detected by the system. +/// Linked to a person (owner) and to license plate detections. +/// +public class Vehicle : Entity, IAuditableEntity +{ + public string? LicensePlate { get; private set; } + public Guid? PersonId { get; private set; } + public string? Make { get; private set; } + public string? Model { get; private set; } + public string? Color { get; private set; } + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } + + // Navigation + public Person? Person { get; private set; } + + private Vehicle() { } // EF Core + + public Vehicle(string? licensePlate, Guid? personId = null, string? make = null, string? model = null, string? color = null) + : base(Guid.NewGuid()) + { + LicensePlate = licensePlate; + PersonId = personId; + Make = make; + Model = model; + Color = color; + } + + public void Update(string? licensePlate, string? make, string? model, string? color) + { + LicensePlate = licensePlate; + Make = make; + Model = model; + Color = color; + } + + public void AssignPerson(Guid personId) => PersonId = personId; +} diff --git a/src/Heimdall.Infrastructure/Data/AppDbContext.cs b/src/Heimdall.Infrastructure/Data/AppDbContext.cs index 5615ff2..76f3c2a 100644 --- a/src/Heimdall.Infrastructure/Data/AppDbContext.cs +++ b/src/Heimdall.Infrastructure/Data/AppDbContext.cs @@ -60,6 +60,12 @@ public class AppDbContext : IdentityDbContext, IApplicat // 2FA recovery codes (stored hashed) public DbSet UserRecoveryCodes => Set(); + // Domain métier (spec 2.1) + public DbSet Vehicles => Set(); + public DbSet Recordings => Set(); + public DbSet LicensePlates => Set(); + public DbSet StoragePolicies => Set(); + public async Task SaveChangesWithRetryAsync(int maxRetries = 3, CancellationToken ct = default) { await DbContextExtensions.SaveChangesWithRetryAsync(this, maxRetries, ct).ConfigureAwait(false); diff --git a/src/Heimdall.Infrastructure/Data/Configurations/CameraConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/CameraConfiguration.cs index f5b8a57..7ac1afe 100644 --- a/src/Heimdall.Infrastructure/Data/Configurations/CameraConfiguration.cs +++ b/src/Heimdall.Infrastructure/Data/Configurations/CameraConfiguration.cs @@ -117,5 +117,13 @@ public class CameraConfiguration : IEntityTypeConfiguration .WithOne(dp => dp.Camera) .HasForeignKey(dp => dp.CameraId) .OnDelete(DeleteBehavior.Cascade); + + // Storage policy (N:1 — plusieurs caméras partagent une politique) + builder.HasOne(c => c.StoragePolicy) + .WithMany() + .HasForeignKey(c => c.StoragePolicyId) + .OnDelete(DeleteBehavior.SetNull); + + builder.HasIndex(c => c.StoragePolicyId); } } diff --git a/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs index 44bb1ce..3926d88 100644 --- a/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs +++ b/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs @@ -37,6 +37,17 @@ public class CameraEventConfiguration : IEntityTypeConfiguration builder.Property(e => e.OccurredAt) .IsRequired(); + builder.Property(e => e.DetectionHash) + .HasMaxLength(128) + .IsUnicode(false); + + builder.Property(e => e.TrackId) + .HasMaxLength(100) + .IsUnicode(false); + + builder.Property(e => e.IsSuppressed) + .HasDefaultValue(false); + builder.Property(e => e.CreatedAt) .HasDefaultValueSql("NOW()"); @@ -51,10 +62,32 @@ public class CameraEventConfiguration : IEntityTypeConfiguration builder.HasIndex(e => e.OccurredAt); + // Indexes déduplication / relations (spec 2.3) + builder.HasIndex(e => e.TrackId); + builder.HasIndex(e => e.DetectionHash); + builder.HasIndex(e => e.ParentEventId); + builder.HasIndex(e => e.VehicleId); + builder.HasIndex(e => e.RecordingId); + // Relationships builder.HasOne(e => e.Camera) .WithMany() .HasForeignKey(e => e.CameraId) .OnDelete(DeleteBehavior.Cascade); + + builder.HasOne(e => e.Vehicle) + .WithMany() + .HasForeignKey(e => e.VehicleId) + .OnDelete(DeleteBehavior.SetNull); + + builder.HasOne(e => e.Recording) + .WithMany() + .HasForeignKey(e => e.RecordingId) + .OnDelete(DeleteBehavior.SetNull); + + builder.HasOne(e => e.ParentEvent) + .WithMany() + .HasForeignKey(e => e.ParentEventId) + .OnDelete(DeleteBehavior.SetNull); } } diff --git a/src/Heimdall.Infrastructure/Data/Configurations/LicensePlateConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/LicensePlateConfiguration.cs new file mode 100644 index 0000000..592d1f8 --- /dev/null +++ b/src/Heimdall.Infrastructure/Data/Configurations/LicensePlateConfiguration.cs @@ -0,0 +1,48 @@ +using Heimdall.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Heimdall.Infrastructure.Data.Configurations; + +public class LicensePlateConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("license_plates"); + + builder.HasKey(p => p.Id); + + builder.Property(p => p.PlateText) + .HasMaxLength(20) + .IsRequired() + .IsUnicode(false); + + builder.Property(p => p.Confidence) + .HasDefaultValue(0.0); + + builder.Property(p => p.CreatedAt) + .HasDefaultValueSql("NOW()"); + + builder.Property(p => p.UpdatedAt) + .HasDefaultValueSql("NOW()"); + + // Indexes (spec 2.3) — GIN trigram pour recherche floue de plaque + builder.HasIndex(p => p.PlateText) + .HasMethod("gin") + .HasOperators("gin_trgm_ops"); + + builder.HasIndex(p => p.VehicleId); + builder.HasIndex(p => p.PersonId); + + // Relationships + builder.HasOne(p => p.Vehicle) + .WithMany() + .HasForeignKey(p => p.VehicleId) + .OnDelete(DeleteBehavior.SetNull); + + builder.HasOne(p => p.Person) + .WithMany() + .HasForeignKey(p => p.PersonId) + .OnDelete(DeleteBehavior.SetNull); + } +} diff --git a/src/Heimdall.Infrastructure/Data/Configurations/RecordingConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/RecordingConfiguration.cs new file mode 100644 index 0000000..e0c82a0 --- /dev/null +++ b/src/Heimdall.Infrastructure/Data/Configurations/RecordingConfiguration.cs @@ -0,0 +1,57 @@ +using Heimdall.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Heimdall.Infrastructure.Data.Configurations; + +public class RecordingConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("recordings"); + + builder.HasKey(r => r.Id); + + builder.Property(r => r.Timestamp) + .IsRequired(); + + builder.Property(r => r.DurationSeconds) + .HasDefaultValue(0.0); + + builder.Property(r => r.StoragePath) + .HasMaxLength(2000) + .IsRequired() + .IsUnicode(false); + + builder.Property(r => r.SizeBytes) + .IsRequired(); + + builder.Property(r => r.StorageProvider) + .HasConversion() + .HasMaxLength(20) + .IsRequired() + .IsUnicode(false); + + builder.Property(r => r.CreatedAt) + .HasDefaultValueSql("NOW()"); + + builder.Property(r => r.UpdatedAt) + .HasDefaultValueSql("NOW()"); + + // Indexes (spec 2.3) + builder.HasIndex(r => new { r.CameraId, r.Timestamp }); // timeline per camera + builder.HasIndex(r => r.StoragePath).IsUnique(); // storage dedup + builder.HasIndex(r => r.StoragePolicyId); + + // Relationships + builder.HasOne(r => r.Camera) + .WithMany() + .HasForeignKey(r => r.CameraId) + .OnDelete(DeleteBehavior.Cascade); + + builder.HasOne(r => r.StoragePolicy) + .WithMany() + .HasForeignKey(r => r.StoragePolicyId) + .OnDelete(DeleteBehavior.SetNull); + } +} diff --git a/src/Heimdall.Infrastructure/Data/Configurations/StoragePolicyConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/StoragePolicyConfiguration.cs new file mode 100644 index 0000000..5e3ab0c --- /dev/null +++ b/src/Heimdall.Infrastructure/Data/Configurations/StoragePolicyConfiguration.cs @@ -0,0 +1,35 @@ +using Heimdall.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Heimdall.Infrastructure.Data.Configurations; + +public class StoragePolicyConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("storage_policies"); + + builder.HasKey(p => p.Id); + + builder.Property(p => p.Name) + .HasMaxLength(100) + .IsRequired() + .IsUnicode(false); + + builder.Property(p => p.RetentionDays) + .IsRequired(); + + builder.Property(p => p.StorageProvider) + .HasConversion() + .HasMaxLength(20) + .IsRequired() + .IsUnicode(false); + + builder.Property(p => p.CreatedAt) + .HasDefaultValueSql("NOW()"); + + builder.Property(p => p.UpdatedAt) + .HasDefaultValueSql("NOW()"); + } +} diff --git a/src/Heimdall.Infrastructure/Data/Configurations/VehicleConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/VehicleConfiguration.cs new file mode 100644 index 0000000..2c65981 --- /dev/null +++ b/src/Heimdall.Infrastructure/Data/Configurations/VehicleConfiguration.cs @@ -0,0 +1,47 @@ +using Heimdall.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Heimdall.Infrastructure.Data.Configurations; + +public class VehicleConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("vehicles"); + + builder.HasKey(v => v.Id); + + builder.Property(v => v.LicensePlate) + .HasMaxLength(20) + .IsUnicode(false); + + builder.Property(v => v.Make) + .HasMaxLength(100) + .IsUnicode(false); + + builder.Property(v => v.Model) + .HasMaxLength(100) + .IsUnicode(false); + + builder.Property(v => v.Color) + .HasMaxLength(50) + .IsUnicode(false); + + builder.Property(v => v.CreatedAt) + .HasDefaultValueSql("NOW()"); + + builder.Property(v => v.UpdatedAt) + .HasDefaultValueSql("NOW()"); + + // Indexes + builder.HasIndex(v => v.LicensePlate); + builder.HasIndex(v => v.PersonId); + + // Relationships + builder.HasOne(v => v.Person) + .WithMany() + .HasForeignKey(v => v.PersonId) + .OnDelete(DeleteBehavior.SetNull); + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/20260811193836_AddBusinessEntities.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260811193836_AddBusinessEntities.Designer.cs new file mode 100644 index 0000000..2ab14c8 --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20260811193836_AddBusinessEntities.Designer.cs @@ -0,0 +1,2214 @@ +// +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("20260811193836_AddBusinessEntities")] + partial class AddBusinessEntities + { + /// + 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.AgentLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("Exception") + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.Property("Level") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("Source") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("TimestampUtc") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AgentId", "TimestampUtc"); + + b.ToTable("agent_log_entries", (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("StoragePolicyId") + .HasColumnType("uuid"); + + 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.HasIndex("StoragePolicyId"); + + 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("DetectionHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("IsSuppressed") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + 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("ParentEventId") + .HasColumnType("uuid"); + + b.Property("RecordingId") + .HasColumnType("uuid"); + + b.Property("SnapshotThumbUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("SnapshotUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("TrackId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("VehicleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("DetectionHash"); + + b.HasIndex("OccurredAt"); + + b.HasIndex("ParentEventId"); + + b.HasIndex("RecordingId"); + + b.HasIndex("TrackId"); + + b.HasIndex("VehicleId"); + + 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.LicensePlate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .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("PersonId") + .HasColumnType("uuid"); + + b.Property("PlateText") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("VehicleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("PersonId"); + + b.HasIndex("PlateText"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("PlateText"), "gin"); + NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex("PlateText"), new[] { "gin_trgm_ops" }); + + b.HasIndex("VehicleId"); + + b.ToTable("license_plates", (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.Recording", 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("DurationSeconds") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.0); + + b.Property("SizeBytes") + .HasColumnType("bigint"); + + b.Property("StoragePath") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("StoragePolicyId") + .HasColumnType("uuid"); + + b.Property("StorageProvider") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("StoragePath") + .IsUnique(); + + b.HasIndex("StoragePolicyId"); + + b.HasIndex("CameraId", "Timestamp"); + + b.ToTable("recordings", (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.SiteCredential", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("LastUsedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("SiteId"); + + b.ToTable("site_credentials", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.StoragePolicy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("RetentionDays") + .HasColumnType("integer"); + + b.Property("StorageProvider") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.ToTable("storage_policies", (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.UserRecoveryCode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CodeHash") + .IsRequired() + .HasMaxLength(64) + .IsUnicode(false) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UsedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("UserId", "CodeHash") + .IsUnique(); + + b.ToTable("user_recovery_codes", (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("Heimdall.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Color") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("LicensePlate") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Make") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Model") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("LicensePlate"); + + b.HasIndex("PersonId"); + + b.ToTable("vehicles", (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.AgentLogEntry", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany() + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Agent"); + }); + + 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.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy") + .WithMany() + .HasForeignKey("StoragePolicyId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Agent"); + + b.Navigation("Site"); + + b.Navigation("StoragePolicy"); + }); + + 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.HasOne("Heimdall.Domain.Entities.CameraEvent", "ParentEvent") + .WithMany() + .HasForeignKey("ParentEventId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Recording", "Recording") + .WithMany() + .HasForeignKey("RecordingId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Camera"); + + b.Navigation("ParentEvent"); + + b.Navigation("Recording"); + + b.Navigation("Vehicle"); + }); + + 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.LicensePlate", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Person"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Recording", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy") + .WithMany() + .HasForeignKey("StoragePolicyId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Camera"); + + b.Navigation("StoragePolicy"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.SiteCredential", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany("Credentials") + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Site"); + }); + + 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("Heimdall.Domain.Entities.Vehicle", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Person"); + }); + + 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"); + + b.Navigation("Credentials"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/20260811193836_AddBusinessEntities.cs b/src/Heimdall.Infrastructure/Migrations/20260811193836_AddBusinessEntities.cs new file mode 100644 index 0000000..8a46134 --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20260811193836_AddBusinessEntities.cs @@ -0,0 +1,355 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Heimdall.Infrastructure.Migrations +{ + /// + public partial class AddBusinessEntities : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + // Extension trigram requise pour l'index GIN sur license_plates(plate_text) + migrationBuilder.Sql("CREATE EXTENSION IF NOT EXISTS pg_trgm;"); + + migrationBuilder.AddColumn( + name: "StoragePolicyId", + table: "cameras", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "DetectionHash", + table: "camera_events", + type: "character varying(128)", + unicode: false, + maxLength: 128, + nullable: true); + + migrationBuilder.AddColumn( + name: "IsSuppressed", + table: "camera_events", + type: "boolean", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "ParentEventId", + table: "camera_events", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "RecordingId", + table: "camera_events", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TrackId", + table: "camera_events", + type: "character varying(100)", + unicode: false, + maxLength: 100, + nullable: true); + + migrationBuilder.AddColumn( + name: "VehicleId", + table: "camera_events", + type: "uuid", + nullable: true); + + migrationBuilder.CreateTable( + name: "storage_policies", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false), + RetentionDays = table.Column(type: "integer", nullable: false), + StorageProvider = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + }, + constraints: table => + { + table.PrimaryKey("PK_storage_policies", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "vehicles", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + LicensePlate = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: true), + PersonId = table.Column(type: "uuid", nullable: true), + Make = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true), + Model = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true), + Color = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + }, + constraints: table => + { + table.PrimaryKey("PK_vehicles", x => x.Id); + table.ForeignKey( + name: "FK_vehicles_persons_PersonId", + column: x => x.PersonId, + principalTable: "persons", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + }); + + migrationBuilder.CreateTable( + name: "recordings", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + CameraId = table.Column(type: "uuid", nullable: false), + Timestamp = table.Column(type: "timestamp with time zone", nullable: false), + DurationSeconds = table.Column(type: "double precision", nullable: false, defaultValue: 0.0), + StoragePath = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: false), + SizeBytes = table.Column(type: "bigint", nullable: false), + StorageProvider = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + StoragePolicyId = table.Column(type: "uuid", nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + }, + constraints: table => + { + table.PrimaryKey("PK_recordings", x => x.Id); + table.ForeignKey( + name: "FK_recordings_cameras_CameraId", + column: x => x.CameraId, + principalTable: "cameras", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_recordings_storage_policies_StoragePolicyId", + column: x => x.StoragePolicyId, + principalTable: "storage_policies", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + }); + + migrationBuilder.CreateTable( + name: "license_plates", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + PlateText = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + VehicleId = table.Column(type: "uuid", nullable: true), + PersonId = table.Column(type: "uuid", nullable: true), + Confidence = table.Column(type: "double precision", nullable: false, defaultValue: 0.0), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + }, + constraints: table => + { + table.PrimaryKey("PK_license_plates", x => x.Id); + table.ForeignKey( + name: "FK_license_plates_persons_PersonId", + column: x => x.PersonId, + principalTable: "persons", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + table.ForeignKey( + name: "FK_license_plates_vehicles_VehicleId", + column: x => x.VehicleId, + principalTable: "vehicles", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + }); + + migrationBuilder.CreateIndex( + name: "IX_cameras_StoragePolicyId", + table: "cameras", + column: "StoragePolicyId"); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_DetectionHash", + table: "camera_events", + column: "DetectionHash"); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_ParentEventId", + table: "camera_events", + column: "ParentEventId"); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_RecordingId", + table: "camera_events", + column: "RecordingId"); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_TrackId", + table: "camera_events", + column: "TrackId"); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_VehicleId", + table: "camera_events", + column: "VehicleId"); + + migrationBuilder.CreateIndex( + name: "IX_license_plates_PersonId", + table: "license_plates", + column: "PersonId"); + + migrationBuilder.CreateIndex( + name: "IX_license_plates_PlateText", + table: "license_plates", + column: "PlateText") + .Annotation("Npgsql:IndexMethod", "gin") + .Annotation("Npgsql:IndexOperators", new[] { "gin_trgm_ops" }); + + migrationBuilder.CreateIndex( + name: "IX_license_plates_VehicleId", + table: "license_plates", + column: "VehicleId"); + + migrationBuilder.CreateIndex( + name: "IX_recordings_CameraId_Timestamp", + table: "recordings", + columns: new[] { "CameraId", "Timestamp" }); + + migrationBuilder.CreateIndex( + name: "IX_recordings_StoragePath", + table: "recordings", + column: "StoragePath", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_recordings_StoragePolicyId", + table: "recordings", + column: "StoragePolicyId"); + + migrationBuilder.CreateIndex( + name: "IX_vehicles_LicensePlate", + table: "vehicles", + column: "LicensePlate"); + + migrationBuilder.CreateIndex( + name: "IX_vehicles_PersonId", + table: "vehicles", + column: "PersonId"); + + migrationBuilder.AddForeignKey( + name: "FK_camera_events_camera_events_ParentEventId", + table: "camera_events", + column: "ParentEventId", + principalTable: "camera_events", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + + migrationBuilder.AddForeignKey( + name: "FK_camera_events_recordings_RecordingId", + table: "camera_events", + column: "RecordingId", + principalTable: "recordings", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + + migrationBuilder.AddForeignKey( + name: "FK_camera_events_vehicles_VehicleId", + table: "camera_events", + column: "VehicleId", + principalTable: "vehicles", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + + migrationBuilder.AddForeignKey( + name: "FK_cameras_storage_policies_StoragePolicyId", + table: "cameras", + column: "StoragePolicyId", + principalTable: "storage_policies", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_camera_events_camera_events_ParentEventId", + table: "camera_events"); + + migrationBuilder.DropForeignKey( + name: "FK_camera_events_recordings_RecordingId", + table: "camera_events"); + + migrationBuilder.DropForeignKey( + name: "FK_camera_events_vehicles_VehicleId", + table: "camera_events"); + + migrationBuilder.DropForeignKey( + name: "FK_cameras_storage_policies_StoragePolicyId", + table: "cameras"); + + migrationBuilder.DropTable( + name: "license_plates"); + + migrationBuilder.DropTable( + name: "recordings"); + + migrationBuilder.DropTable( + name: "vehicles"); + + migrationBuilder.DropTable( + name: "storage_policies"); + + migrationBuilder.DropIndex( + name: "IX_cameras_StoragePolicyId", + table: "cameras"); + + migrationBuilder.DropIndex( + name: "IX_camera_events_DetectionHash", + table: "camera_events"); + + migrationBuilder.DropIndex( + name: "IX_camera_events_ParentEventId", + table: "camera_events"); + + migrationBuilder.DropIndex( + name: "IX_camera_events_RecordingId", + table: "camera_events"); + + migrationBuilder.DropIndex( + name: "IX_camera_events_TrackId", + table: "camera_events"); + + migrationBuilder.DropIndex( + name: "IX_camera_events_VehicleId", + table: "camera_events"); + + migrationBuilder.DropColumn( + name: "StoragePolicyId", + table: "cameras"); + + migrationBuilder.DropColumn( + name: "DetectionHash", + table: "camera_events"); + + migrationBuilder.DropColumn( + name: "IsSuppressed", + table: "camera_events"); + + migrationBuilder.DropColumn( + name: "ParentEventId", + table: "camera_events"); + + migrationBuilder.DropColumn( + name: "RecordingId", + table: "camera_events"); + + migrationBuilder.DropColumn( + name: "TrackId", + table: "camera_events"); + + migrationBuilder.DropColumn( + name: "VehicleId", + table: "camera_events"); + } + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs index 0d308fb..fe066c1 100644 --- a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs +++ b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs @@ -598,6 +598,9 @@ namespace Heimdall.Infrastructure.Migrations .IsUnicode(false) .HasColumnType("character varying(20)"); + b.Property("StoragePolicyId") + .HasColumnType("uuid"); + b.Property("SubRtspUrl") .HasMaxLength(1000) .IsUnicode(false) @@ -618,6 +621,8 @@ namespace Heimdall.Infrastructure.Migrations b.HasIndex("SiteId"); + b.HasIndex("StoragePolicyId"); + b.ToTable("cameras", (string)null); }); @@ -917,6 +922,16 @@ namespace Heimdall.Infrastructure.Migrations .HasColumnType("timestamp with time zone") .HasDefaultValueSql("NOW()"); + b.Property("DetectionHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("IsSuppressed") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + b.Property("Label") .HasMaxLength(200) .IsUnicode(false) @@ -928,6 +943,12 @@ namespace Heimdall.Infrastructure.Migrations b.Property("OccurredAt") .HasColumnType("timestamp with time zone"); + b.Property("ParentEventId") + .HasColumnType("uuid"); + + b.Property("RecordingId") + .HasColumnType("uuid"); + b.Property("SnapshotThumbUrl") .HasMaxLength(2000) .IsUnicode(false) @@ -938,6 +959,11 @@ namespace Heimdall.Infrastructure.Migrations .IsUnicode(false) .HasColumnType("character varying(2000)"); + b.Property("TrackId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + b.Property("Type") .HasColumnType("integer"); @@ -946,10 +972,23 @@ namespace Heimdall.Infrastructure.Migrations .HasColumnType("timestamp with time zone") .HasDefaultValueSql("NOW()"); + b.Property("VehicleId") + .HasColumnType("uuid"); + b.HasKey("Id"); + b.HasIndex("DetectionHash"); + b.HasIndex("OccurredAt"); + b.HasIndex("ParentEventId"); + + b.HasIndex("RecordingId"); + + b.HasIndex("TrackId"); + + b.HasIndex("VehicleId"); + b.HasIndex("CameraId", "OccurredAt") .IsDescending(false, true); @@ -1081,6 +1120,53 @@ namespace Heimdall.Infrastructure.Migrations b.ToTable("known_faces", (string)null); }); + modelBuilder.Entity("Heimdall.Domain.Entities.LicensePlate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .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("PersonId") + .HasColumnType("uuid"); + + b.Property("PlateText") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("VehicleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("PersonId"); + + b.HasIndex("PlateText"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("PlateText"), "gin"); + NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex("PlateText"), new[] { "gin_trgm_ops" }); + + b.HasIndex("VehicleId"); + + b.ToTable("license_plates", (string)null); + }); + modelBuilder.Entity("Heimdall.Domain.Entities.Notification", b => { b.Property("Id") @@ -1248,6 +1334,63 @@ namespace Heimdall.Infrastructure.Migrations b.ToTable("persons", (string)null); }); + modelBuilder.Entity("Heimdall.Domain.Entities.Recording", 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("DurationSeconds") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.0); + + b.Property("SizeBytes") + .HasColumnType("bigint"); + + b.Property("StoragePath") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("StoragePolicyId") + .HasColumnType("uuid"); + + b.Property("StorageProvider") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("StoragePath") + .IsUnique(); + + b.HasIndex("StoragePolicyId"); + + b.HasIndex("CameraId", "Timestamp"); + + b.ToTable("recordings", (string)null); + }); + modelBuilder.Entity("Heimdall.Domain.Entities.RevokedRefreshToken", b => { b.Property("Id") @@ -1383,6 +1526,42 @@ namespace Heimdall.Infrastructure.Migrations b.ToTable("site_credentials", (string)null); }); + modelBuilder.Entity("Heimdall.Domain.Entities.StoragePolicy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("RetentionDays") + .HasColumnType("integer"); + + b.Property("StorageProvider") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.ToTable("storage_policies", (string)null); + }); + modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => { b.Property("UserId") @@ -1504,6 +1683,54 @@ namespace Heimdall.Infrastructure.Migrations b.ToTable("user_sites", (string)null); }); + modelBuilder.Entity("Heimdall.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Color") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("LicensePlate") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Make") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Model") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("LicensePlate"); + + b.HasIndex("PersonId"); + + b.ToTable("vehicles", (string)null); + }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") @@ -1673,9 +1900,16 @@ namespace Heimdall.Infrastructure.Migrations .OnDelete(DeleteBehavior.Restrict) .IsRequired(); + b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy") + .WithMany() + .HasForeignKey("StoragePolicyId") + .OnDelete(DeleteBehavior.SetNull); + b.Navigation("Agent"); b.Navigation("Site"); + + b.Navigation("StoragePolicy"); }); modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => @@ -1738,7 +1972,28 @@ namespace Heimdall.Infrastructure.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("Heimdall.Domain.Entities.CameraEvent", "ParentEvent") + .WithMany() + .HasForeignKey("ParentEventId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Recording", "Recording") + .WithMany() + .HasForeignKey("RecordingId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.SetNull); + b.Navigation("Camera"); + + b.Navigation("ParentEvent"); + + b.Navigation("Recording"); + + b.Navigation("Vehicle"); }); modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => @@ -1763,6 +2018,41 @@ namespace Heimdall.Infrastructure.Migrations b.Navigation("Person"); }); + modelBuilder.Entity("Heimdall.Domain.Entities.LicensePlate", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Person"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Recording", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy") + .WithMany() + .HasForeignKey("StoragePolicyId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Camera"); + + b.Navigation("StoragePolicy"); + }); + modelBuilder.Entity("Heimdall.Domain.Entities.SiteCredential", b => { b.HasOne("Heimdall.Domain.Entities.Site", "Site") @@ -1812,6 +2102,16 @@ namespace Heimdall.Infrastructure.Migrations b.Navigation("User"); }); + modelBuilder.Entity("Heimdall.Domain.Entities.Vehicle", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Person"); + }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Heimdall.Domain.Entities.AppRole", null) diff --git a/tests/Heimdall.Domain.Tests/Entities/BusinessEntityTests.cs b/tests/Heimdall.Domain.Tests/Entities/BusinessEntityTests.cs new file mode 100644 index 0000000..b84c551 --- /dev/null +++ b/tests/Heimdall.Domain.Tests/Entities/BusinessEntityTests.cs @@ -0,0 +1,158 @@ +using Heimdall.Domain.Entities; +using Heimdall.Domain.Enums; +using Shouldly; + +namespace Heimdall.Domain.Tests.Entities; + +public class BusinessEntityTests +{ + // ─── StoragePolicy ───────────────────────────────────────────── + + [Fact] + public void StoragePolicy_create_should_set_properties() + { + var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3); + + policy.Name.ShouldBe("30 jours"); + policy.RetentionDays.ShouldBe(30); + policy.StorageProvider.ShouldBe(StorageProvider.S3); + policy.Id.ShouldNotBe(Guid.Empty); + } + + [Fact] + public void StoragePolicy_update_should_change_values() + { + var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3); + + policy.Update("90 jours", 90, StorageProvider.Local); + + policy.Name.ShouldBe("90 jours"); + policy.RetentionDays.ShouldBe(90); + policy.StorageProvider.ShouldBe(StorageProvider.Local); + } + + // ─── Vehicle ─────────────────────────────────────────────────── + + [Fact] + public void Vehicle_create_should_set_properties() + { + var vehicle = new Vehicle("AB-123-CD", null, "Renault", "Clio", "Noir"); + + vehicle.LicensePlate.ShouldBe("AB-123-CD"); + vehicle.Make.ShouldBe("Renault"); + vehicle.Model.ShouldBe("Clio"); + vehicle.Color.ShouldBe("Noir"); + } + + [Fact] + public void Vehicle_assign_person_should_set_relation() + { + var vehicle = new Vehicle("AB-123-CD"); + var personId = Guid.NewGuid(); + + vehicle.AssignPerson(personId); + + vehicle.PersonId.ShouldBe(personId); + } + + // ─── Recording ───────────────────────────────────────────────── + + [Fact] + public void Recording_create_should_set_properties() + { + var cameraId = Guid.NewGuid(); + var policyId = Guid.NewGuid(); + var ts = new DateTime(2026, 7, 1, 12, 0, 0, DateTimeKind.Utc); + var recording = new Recording(cameraId, ts, 60.0, "recordings/2026/07/01/12/cam1.mp4", 10_000_000, StorageProvider.S3, policyId); + + recording.CameraId.ShouldBe(cameraId); + recording.Timestamp.ShouldBe(ts); + recording.DurationSeconds.ShouldBe(60.0); + recording.StoragePath.ShouldBe("recordings/2026/07/01/12/cam1.mp4"); + recording.SizeBytes.ShouldBe(10_000_000L); + recording.StorageProvider.ShouldBe(StorageProvider.S3); + recording.StoragePolicyId.ShouldBe(policyId); + } + + [Fact] + public void Recording_assign_policy_should_update_relation() + { + var recording = new Recording(Guid.NewGuid(), DateTime.UtcNow, 60, "path.mp4", 100, StorageProvider.Local); + var policyId = Guid.NewGuid(); + + recording.AssignStoragePolicy(policyId); + + recording.StoragePolicyId.ShouldBe(policyId); + } + + // ─── LicensePlate ────────────────────────────────────────────── + + [Fact] + public void LicensePlate_create_should_set_properties() + { + var plate = new LicensePlate("AB-123-CD", null, null, 0.98); + + plate.PlateText.ShouldBe("AB-123-CD"); + plate.Confidence.ShouldBe(0.98); + } + + [Fact] + public void LicensePlate_assign_vehicle_and_person_should_set_relations() + { + var plate = new LicensePlate("AB-123-CD"); + var vehicleId = Guid.NewGuid(); + var personId = Guid.NewGuid(); + + plate.AssignVehicle(vehicleId); + plate.AssignPerson(personId); + + plate.VehicleId.ShouldBe(vehicleId); + plate.PersonId.ShouldBe(personId); + } + + // ─── CameraEvent — relations enrichies (spec 2.2) ───────────── + + [Fact] + public void CameraEvent_assign_vehicle_recording_and_parent_should_set_relations() + { + var evt = new CameraEvent(Guid.NewGuid(), EventType.VehicleDetected, 0.9); + var vehicleId = Guid.NewGuid(); + var recordingId = Guid.NewGuid(); + var parentId = Guid.NewGuid(); + + evt.AssignVehicle(vehicleId); + evt.AssignRecording(recordingId); + evt.AssignParentEvent(parentId); + + evt.VehicleId.ShouldBe(vehicleId); + evt.RecordingId.ShouldBe(recordingId); + evt.ParentEventId.ShouldBe(parentId); + } + + [Fact] + public void CameraEvent_dedup_fields_should_be_settable() + { + var evt = new CameraEvent(Guid.NewGuid(), EventType.PersonDetected, 0.85); + + evt.SetTrackId("track-42"); + evt.SetDetectionHash("sha256:abc123"); + evt.SetSuppressed(true); + + evt.TrackId.ShouldBe("track-42"); + evt.DetectionHash.ShouldBe("sha256:abc123"); + evt.IsSuppressed.ShouldBeTrue(); + } + + // ─── Camera → StoragePolicy (N:1) ────────────────────────────── + + [Fact] + public void Camera_assign_storage_policy_should_set_relation() + { + var camera = new Camera(Guid.NewGuid(), "Entrée"); + var policyId = Guid.NewGuid(); + + camera.AssignStoragePolicy(policyId); + + camera.StoragePolicyId.ShouldBe(policyId); + } +} diff --git a/tests/Heimdall.Infrastructure.Tests/BusinessEntityPersistenceTests.cs b/tests/Heimdall.Infrastructure.Tests/BusinessEntityPersistenceTests.cs new file mode 100644 index 0000000..68bf5ff --- /dev/null +++ b/tests/Heimdall.Infrastructure.Tests/BusinessEntityPersistenceTests.cs @@ -0,0 +1,196 @@ +using Heimdall.Domain.Entities; +using Heimdall.Domain.Enums; +using Heimdall.Infrastructure.Data; +using Heimdall.Infrastructure.Data.Interceptors; +using Microsoft.EntityFrameworkCore; +using Shouldly; + +using Heimdall.TestCommon; + +namespace Heimdall.Infrastructure.Tests; + +/// +/// Validation des entités métier (spec 2.1/2.2) sur PostgreSQL réel : +/// Vehicle, Recording, LicensePlate, StoragePolicy + relations CameraEvent→Vehicle/Recording, +/// Camera→StoragePolicy N:1. +/// +[Collection("PostgresInfra")] +public class BusinessEntityPersistenceTests : IAsyncLifetime +{ + private readonly IDbContextFactory _dbFactory; + + public BusinessEntityPersistenceTests(PostgreSqlContainerFixture postgres) + { + _dbFactory = CreateFactory(postgres.ConnectionString); + } + + public async Task InitializeAsync() + { + await ResetDatabaseAsync(); + } + + public Task DisposeAsync() => Task.CompletedTask; + + private async Task ResetDatabaseAsync() + { + await using var db = await _dbFactory.CreateDbContextAsync(); + await db.Database.ExecuteSqlRawAsync( + "TRUNCATE TABLE license_plates, recordings, vehicles, storage_policies, camera_events, cameras, sites RESTART IDENTITY CASCADE"); + } + + private static TestDbContextFactory CreateFactory(string connectionString) + { + var opts = new DbContextOptionsBuilder() + .UseNpgsql(connectionString, npgsql => + npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "public")) + .Options; + + // Ensure tables exist (l'extension pg_trgm est requise pour l'index GIN trigram) + using var conn = new Npgsql.NpgsqlConnection(connectionString); + conn.Open(); + using (var cmd = conn.CreateCommand()) + { + cmd.CommandText = "CREATE EXTENSION IF NOT EXISTS pg_trgm;"; + cmd.ExecuteNonQuery(); + } + using var ctx = new AppDbContext(opts, new AuditInterceptor()); + ctx.Database.EnsureCreated(); + + return new TestDbContextFactory(opts); + } + + [Fact] + public async Task StoragePolicy_can_be_created_and_shared_by_cameras() + { + await using var db = await _dbFactory.CreateDbContextAsync(); + var site = new Site("Biz Site", "test", "UTC"); + db.Sites.Add(site); + await db.SaveChangesAsync(); + + var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3); + db.StoragePolicies.Add(policy); + await db.SaveChangesAsync(); + + var cam1 = new Camera(site.Id, "Cam-1"); + cam1.AssignStoragePolicy(policy.Id); + var cam2 = new Camera(site.Id, "Cam-2"); + cam2.AssignStoragePolicy(policy.Id); + db.Cameras.AddRange(cam1, cam2); + await db.SaveChangesAsync(); + + // Recharger : les 2 caméras partagent la même politique (N:1) + var reloaded = await db.Cameras + .Include(c => c.StoragePolicy) + .Where(c => c.SiteId == site.Id) + .ToListAsync(); + reloaded.Count.ShouldBe(2); + reloaded.ShouldAllBe(c => c.StoragePolicyId == policy.Id); + reloaded.ShouldAllBe(c => c.StoragePolicy!.Name == "30 jours"); + } + + [Fact] + public async Task CameraEvent_can_link_vehicle_and_recording() + { + await using var db = await _dbFactory.CreateDbContextAsync(); + var site = new Site("Biz Site 2", "test", "UTC"); + db.Sites.Add(site); + await db.SaveChangesAsync(); + + var camera = new Camera(site.Id, "Cam-Event"); + db.Cameras.Add(camera); + await db.SaveChangesAsync(); + + var vehicle = new Vehicle("AB-123-CD", null, "Renault", "Clio", "Noir"); + db.Vehicles.Add(vehicle); + await db.SaveChangesAsync(); + + var recording = new Recording(camera.Id, DateTime.UtcNow, 60, "rec/1.mp4", 1000, StorageProvider.S3); + db.Recordings.Add(recording); + await db.SaveChangesAsync(); + + var evt = new CameraEvent(camera.Id, EventType.VehicleDetected, 0.92); + evt.AssignVehicle(vehicle.Id); + evt.AssignRecording(recording.Id); + evt.SetTrackId("track-1"); + evt.SetDetectionHash("hash-1"); + db.CameraEvents.Add(evt); + await db.SaveChangesAsync(); + + var reloaded = await db.CameraEvents + .Include(e => e.Vehicle) + .Include(e => e.Recording) + .SingleAsync(e => e.Id == evt.Id); + reloaded.VehicleId.ShouldBe(vehicle.Id); + reloaded.Vehicle!.LicensePlate.ShouldBe("AB-123-CD"); + reloaded.RecordingId.ShouldBe(recording.Id); + reloaded.Recording!.StoragePath.ShouldBe("rec/1.mp4"); + reloaded.TrackId.ShouldBe("track-1"); + reloaded.DetectionHash.ShouldBe("hash-1"); + } + + [Fact] + public async Task LicensePlate_can_link_vehicle_and_person() + { + await using var db = await _dbFactory.CreateDbContextAsync(); + var person = new Person("Jean Dupont"); + db.Persons.Add(person); + await db.SaveChangesAsync(); + + var vehicle = new Vehicle("AB-123-CD"); + vehicle.AssignPerson(person.Id); + db.Vehicles.Add(vehicle); + await db.SaveChangesAsync(); + + var plate = new LicensePlate("AB-123-CD", vehicle.Id, person.Id, 0.98); + db.LicensePlates.Add(plate); + await db.SaveChangesAsync(); + + var reloaded = await db.LicensePlates + .Include(p => p.Vehicle) + .Include(p => p.Person) + .SingleAsync(p => p.Id == plate.Id); + reloaded.PlateText.ShouldBe("AB-123-CD"); + reloaded.VehicleId.ShouldBe(vehicle.Id); + reloaded.PersonId.ShouldBe(person.Id); + reloaded.Vehicle!.LicensePlate.ShouldBe("AB-123-CD"); + reloaded.Person!.DisplayName.ShouldBe("Jean Dupont"); + } + + [Fact] + public async Task CameraEvent_parent_child_hierarchy_works() + { + await using var db = await _dbFactory.CreateDbContextAsync(); + var site = new Site("Biz Site 3", "test", "UTC"); + db.Sites.Add(site); + await db.SaveChangesAsync(); + + var camera = new Camera(site.Id, "Cam-Hier"); + db.Cameras.Add(camera); + await db.SaveChangesAsync(); + + var parent = new CameraEvent(camera.Id, EventType.MotionDetected, 0.8); + db.CameraEvents.Add(parent); + await db.SaveChangesAsync(); + + var child = new CameraEvent(camera.Id, EventType.PersonDetected, 0.95); + child.AssignParentEvent(parent.Id); + db.CameraEvents.Add(child); + await db.SaveChangesAsync(); + + var reloaded = await db.CameraEvents + .Include(e => e.ParentEvent) + .SingleAsync(e => e.Id == child.Id); + reloaded.ParentEventId.ShouldBe(parent.Id); + reloaded.ParentEvent!.Type.ShouldBe(EventType.MotionDetected); + } + + private sealed class TestDbContextFactory(DbContextOptions opts) + : IDbContextFactory + { + private static readonly AuditInterceptor Audit = new(); + + public AppDbContext CreateDbContext() => new(opts, Audit); + public Task CreateDbContextAsync(CancellationToken ct = default) + => Task.FromResult(new AppDbContext(opts, Audit)); + } +}