using ZB.MOM.WW.Audit; using ZB.MOM.WW.ScadaBridge.Commons.Types.Audit; using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums; namespace ZB.MOM.WW.ScadaBridge.ManagementService; /// /// Flat, wire-shape view of a canonical for the /// management CLI's /api/audit/query + /api/audit/export endpoints. C3 /// (Task 2.5) made the canonical record the repository seam type; this DTO preserves the /// existing 24-field JSON/CSV shape the CLI consumes by decomposing the canonical row /// (via ) at the endpoint boundary. /// public sealed record AuditExportRow { /// Idempotency key. public Guid EventId { get; init; } /// UTC timestamp when the audited action occurred. public DateTime OccurredAtUtc { get; init; } /// UTC ingest timestamp; null until ingest. public DateTime? IngestedAtUtc { get; init; } /// Trust-boundary channel. public AuditChannel Channel { get; init; } /// Specific event kind. public AuditKind Kind { get; init; } /// Per-operation correlation id. public Guid? CorrelationId { get; init; } /// Originating execution id. public Guid? ExecutionId { get; init; } /// Spawning execution id; null for top-level runs. public Guid? ParentExecutionId { get; init; } /// Site id where the action originated. public string? SourceSiteId { get; init; } /// Cluster node that emitted the event. public string? SourceNode { get; init; } /// Instance id where the action originated. public string? SourceInstanceId { get; init; } /// Script that initiated the action. public string? SourceScript { get; init; } /// Authenticated actor. public string? Actor { get; init; } /// Target of the action. public string? Target { get; init; } /// Lifecycle status. public AuditStatus Status { get; init; } /// HTTP status code where applicable. public int? HttpStatus { get; init; } /// Duration of the action in ms. public int? DurationMs { get; init; } /// Human-readable error summary. public string? ErrorMessage { get; init; } /// Verbose error detail. public string? ErrorDetail { get; init; } /// Truncated/redacted request summary. public string? RequestSummary { get; init; } /// Truncated/redacted response summary. public string? ResponseSummary { get; init; } /// True when summaries were truncated. public bool PayloadTruncated { get; init; } /// Free-form JSON extension. public string? Extra { get; init; } /// Site-local forwarding state; always null on the central read path. public AuditForwardState? ForwardState { get; init; } /// Decomposes a canonical into this flat export shape. /// The audit event to decompose into the flat export row. /// A new populated from the decomposed canonical row. public static AuditExportRow From(AuditEvent evt) { var r = AuditRowProjection.Decompose(evt); return new AuditExportRow { EventId = r.EventId, OccurredAtUtc = r.OccurredAtUtc, IngestedAtUtc = r.IngestedAtUtc, Channel = r.Channel, Kind = r.Kind, CorrelationId = r.CorrelationId, ExecutionId = r.ExecutionId, ParentExecutionId = r.ParentExecutionId, SourceSiteId = r.SourceSiteId, SourceNode = r.SourceNode, SourceInstanceId = r.SourceInstanceId, SourceScript = r.SourceScript, Actor = r.Actor, Target = r.Target, Status = r.Status, HttpStatus = r.HttpStatus, DurationMs = r.DurationMs, ErrorMessage = r.ErrorMessage, ErrorDetail = r.ErrorDetail, RequestSummary = r.RequestSummary, ResponseSummary = r.ResponseSummary, PayloadTruncated = r.PayloadTruncated, Extra = r.Extra, ForwardState = null, }; } }