namespace SQLInsight.Core.Data;
/// A distribution agent's latest run, from MSdistribution_history.
/// 1 start, 2 succeed, 3 in progress, 4 idle, 5 retry, 6 fail.
/// The agent's message; can name servers and objects.
public sealed record DistributionAgent(string Name, string? PublisherDatabase, int? RunStatus, DateTimeOffset? LastRunAt, long? DeliveryLatencyMs, string? Comment)
{
public bool Failed => RunStatus is 5 or 6;
public string StatusText => RunStatus switch
{
1 => "startet",
2 => "lykkedes",
3 => "i gang",
4 => "venter (intet at levere)",
5 => "prøver igen",
6 => "fejlede",
_ => "ukendt",
};
}
/// Replication as seen from the distributor, every 15 minutes.
public sealed record ReplicationSnapshot
{
public required DateTimeOffset CapturedAt { get; init; }
/// The instance is a distributor (has a distribution database).
public bool IsDistributor { get; init; }
public string? DistributionDatabase { get; init; }
/// Why the distribution database could not be read (typically no SELECT rights); null when it could.
public string? Unavailable { get; init; }
/// SQL Server's error message when it could not be read. Names the agent's login: sensitive (local UI only).
public string? UnavailableDetail { get; init; }
public IReadOnlyList Agents { get; init; } = [];
/// Rows in MSrepl_errors the last 24 hours.
public int ErrorsLastDay { get; init; }
/// Delivery latency above this (ms) is a finding.
public long LatencyThresholdMs { get; init; } = 300_000;
}