Files
Heimdall/src/Heimdall.Domain/Entities/CameraEvent.cs
T

84 lines
3.5 KiB
C#
Raw Normal View History

using Heimdall.Domain.Enums;
using Heimdall.Domain.Primitives;
namespace Heimdall.Domain.Entities;
/// <summary>
/// An event detected on a camera stream — motion, person, vehicle, face, etc.
/// Stores AI detection results with confidence, bounding boxes, and snapshots.
/// </summary>
public class CameraEvent : Entity<Guid>, IAuditableEntity
{
public Guid CameraId { get; private set; }
public Guid? AgentId { get; private set; }
public EventType Type { get; private set; }
public double Confidence { get; private set; }
public string? Label { get; private set; } // Human-readable label (e.g. "John Doe", "AB-123-CD")
public string? SnapshotUrl { get; private set; } // S3 key or URL to snapshot image
public string? SnapshotThumbUrl { get; private set; } // Thumbnail S3 key or URL
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) ─────────────────────────────
/// <summary>Vehicle linked to this event (Event → Vehicle N:1).</summary>
public Guid? VehicleId { get; private set; }
/// <summary>Recording segment linked to this event (Event → Recording N:1).</summary>
public Guid? RecordingId { get; private set; }
/// <summary>Parent event for event hierarchies (Event → Event N:1).</summary>
public Guid? ParentEventId { get; private set; }
// ── Déduplication (spec 2.1) ────────────────────────────────────
/// <summary>Stable hash of detection content used for deduplication.</summary>
public string? DetectionHash { get; private set; }
/// <summary>True when the event was suppressed (duplicate / low value).</summary>
public bool IsSuppressed { get; private set; }
/// <summary>Tracking identifier grouping frames of the same object.</summary>
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
public CameraEvent(Guid cameraId, EventType type, double confidence, DateTime? occurredAt = null)
: base(Guid.NewGuid())
{
CameraId = cameraId;
Type = type;
Confidence = confidence;
OccurredAt = occurredAt ?? DateTime.UtcNow;
}
public void SetSnapshot(string snapshotUrl, string? thumbUrl = null)
{
SnapshotUrl = snapshotUrl;
if (thumbUrl is not null)
SnapshotThumbUrl = thumbUrl;
}
public void SetMetadata(string? label, string? metadataJson)
{
Label = label;
MetadataJson = metadataJson;
}
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;
}