namespace SQLInsight.Core.Data;
///
/// Always On availability group state as seen from this instance. A primary sees all replicas; a secondary only itself.
///
public sealed record AvailabilityGroupSnapshot
{
public required DateTimeOffset CapturedAt { get; init; }
public required IReadOnlyList Replicas { get; init; }
public required IReadOnlyList Databases { get; init; }
/// The Windows cluster's nodes and witness (sys.dm_hadr_cluster_members); empty without a WSFC.
public IReadOnlyList ClusterMembers { get; init; } = [];
}
public sealed record ReplicaState
{
public required string Group { get; init; }
public required string Replica { get; init; }
public bool IsLocal { get; init; }
/// PRIMARY, SECONDARY or RESOLVING; null when this instance cannot see the replica's state.
public string? Role { get; init; }
public string? ConnectedState { get; init; }
/// HEALTHY, PARTIALLY_HEALTHY or NOT_HEALTHY.
public string? SynchronizationHealth { get; init; }
public string? AvailabilityMode { get; init; }
public string? FailoverMode { get; init; }
}
public sealed record DatabaseReplicaState
{
public required string Group { get; init; }
public required string Database { get; init; }
public required string Replica { get; init; }
public bool IsLocal { get; init; }
public bool IsPrimaryReplica { get; init; }
public string? SynchronizationState { get; init; }
public string? SynchronizationHealth { get; init; }
public bool IsSuspended { get; init; }
public string? SuspendReason { get; init; }
/// Log not yet sent to this secondary, in KB.
public long? LogSendQueueKb { get; init; }
public long? LogSendRateKbPerSecond { get; init; }
/// Log received but not yet redone on this secondary, in KB.
public long? RedoQueueKb { get; init; }
public long? RedoRateKbPerSecond { get; init; }
public DateTime? LastCommitTime { get; init; }
}
///
/// SQL Server Agent: whether it runs, and the latest outcome of each job.
///
public sealed record AgentJobSnapshot
{
public required DateTimeOffset CapturedAt { get; init; }
/// False when no SQL Agent session exists (the service is stopped).
public required bool IsAgentRunning { get; init; }
public required IReadOnlyList Jobs { get; init; }
}
public sealed record AgentJob
{
public required string Name { get; init; }
public bool IsEnabled { get; init; }
/// 0 failed, 1 succeeded, 2 retry, 3 canceled, 4 in progress; null if never run.
public int? LastRunStatus { get; init; }
public DateTime? LastRunAt { get; init; }
/// The message of the most recent failed step, which says why (the job-level message does not).
public string? LastFailedStepMessage { get; init; }
public string? LastFailedStepName { get; init; }
public int FailuresLastDay { get; init; }
public bool LastRunFailed => LastRunStatus == 0;
}
/// CLUSTER_NODE, DISK_WITNESS, FILE_SHARE_WITNESS, CLOUD_WITNESS.
/// 0 offline, 1 up.
public sealed record ClusterMember(string Name, string Type, int State, string StateText, int? QuorumVotes)
{
public bool IsUp => State == 1;
}