namespace Tiku.Application.PlatformAdmin.Operations;

public sealed record PlatformDependencyHealth(
    bool Healthy,
    bool Database,
    bool RedisConfigured,
    bool RedisReady,
    bool WorkerReady,
    DateTimeOffset? LastHeartbeatAt,
    bool ClamAv,
    string StorageProvider,
    bool StorageConfigured,
    DateTimeOffset CheckedAt);

public sealed record PlatformWorkerState(
    string WorkerId,
    string Processor,
    DateTimeOffset StartedAt,
    DateTimeOffset LastHeartbeatAt,
    DateTimeOffset? LastIterationStartedAt,
    DateTimeOffset? LastIterationCompletedAt,
    DateTimeOffset? LastSucceededAt,
    string? LastError,
    bool IsRunning,
    bool Stale);

public sealed record PlatformMetricCount(string Status, int Count);

public sealed record PlatformJobMetrics(
    IReadOnlyCollection<PlatformMetricCount> Counts,
    DateTimeOffset? OldestPendingAt,
    double QueueAgeSeconds,
    int ExpiredLeases,
    DateTimeOffset CheckedAt);

public sealed record PlatformGovernanceMetrics(
    IReadOnlyCollection<PlatformMetricCount> Approvals,
    int ExpiredPending,
    int ConfigurationDrafts,
    IReadOnlyCollection<PlatformMetricCount> Notifications,
    DateTimeOffset CheckedAt);

public interface IPlatformOperationsQueryService
{
    Task<PlatformDependencyHealth> GetHealthAsync(CancellationToken cancellationToken = default);
    Task<IReadOnlyCollection<PlatformWorkerState>> GetWorkersAsync(CancellationToken cancellationToken = default);
    Task<PlatformJobMetrics> GetJobMetricsAsync(CancellationToken cancellationToken = default);
    Task<PlatformGovernanceMetrics> GetGovernanceMetricsAsync(CancellationToken cancellationToken = default);
}