// -----------------------------------------------------------------------------
// ChainVerificationResult.cs
// Sprint: SPRINT_20260105_002_002_SCHEDULER_hlc_queue_chain
// Task: SQC-015 - Implement chain verification
// -----------------------------------------------------------------------------
using StellaOps.Scheduler.Persistence.Postgres;
namespace StellaOps.Scheduler.Queue.Models;
///
/// Result of chain verification.
///
public sealed record ChainVerificationResult
{
///
/// Whether the chain is valid (no issues found).
///
public required bool IsValid { get; init; }
///
/// Number of entries checked.
///
public required int EntriesChecked { get; init; }
///
/// List of issues found during verification.
///
public required IReadOnlyList Issues { get; init; }
///
/// First valid entry's HLC timestamp (null if no entries).
///
public string? FirstHlc { get; init; }
///
/// Last valid entry's HLC timestamp (null if no entries).
///
public string? LastHlc { get; init; }
///
/// Head link after verification (null if no entries).
///
public byte[]? HeadLink { get; init; }
///
/// Get a summary of the verification result.
///
public string GetSummary()
{
if (IsValid)
{
return $"Chain valid: {EntriesChecked} entries verified, range [{FirstHlc}, {LastHlc}], head {SchedulerChainLinking.ToHexString(HeadLink)}";
}
return $"Chain INVALID: {Issues.Count} issue(s) found in {EntriesChecked} entries";
}
}
///
/// Represents a single issue found during chain verification.
///
public sealed record ChainVerificationIssue
{
///
/// Job ID where the issue was found.
///
public required Guid JobId { get; init; }
///
/// HLC timestamp of the problematic entry.
///
public required string THlc { get; init; }
///
/// Type of issue found.
///
public required ChainVerificationIssueType IssueType { get; init; }
///
/// Human-readable description of the issue.
///
public required string Description { get; init; }
///
/// Expected value (for comparison issues).
///
public string? Expected { get; init; }
///
/// Actual value found (for comparison issues).
///
public string? Actual { get; init; }
}
///
/// Types of chain verification issues.
///
public enum ChainVerificationIssueType
{
///
/// The prev_link doesn't match the previous entry's link.
///
PrevLinkMismatch,
///
/// The stored link doesn't match the computed link.
///
LinkMismatch,
///
/// The HLC timestamp is out of order.
///
HlcOrderViolation,
///
/// The payload hash has invalid length.
///
InvalidPayloadHash,
///
/// The link has invalid length.
///
InvalidLinkLength
}