namespace ZB.MOM.WW.MxGateway.Server.Dashboard;

/// <summary>
///     Snapshot of the Galaxy Repository (ZB) browse state surfaced on the dashboard.
///     Populated by <see cref="GalaxySummaryCache"/> on a background refresh cadence so
///     the dashboard never blocks on SQL.
/// </summary>
public sealed record DashboardGalaxySummary(
    DashboardGalaxyStatus Status,
    DateTimeOffset? LastQueriedAt,
    DateTimeOffset? LastSuccessAt,
    DateTimeOffset? LastDeployTime,
    string? LastError,
    int ObjectCount,
    int AreaCount,
    int AttributeCount,
    int HistorizedAttributeCount,
    int AlarmAttributeCount,
    IReadOnlyList<DashboardGalaxyTemplateUsage> TopTemplates,
    IReadOnlyList<DashboardGalaxyCategoryCount> ObjectCategories)
{
    /// <summary>Gets the unknown Galaxy status placeholder.</summary>
    public static DashboardGalaxySummary Unknown { get; } = new(
        DashboardGalaxyStatus.Unknown,
        LastQueriedAt: null,
        LastSuccessAt: null,
        LastDeployTime: null,
        LastError: null,
        ObjectCount: 0,
        AreaCount: 0,
        AttributeCount: 0,
        HistorizedAttributeCount: 0,
        AlarmAttributeCount: 0,
        TopTemplates: Array.Empty<DashboardGalaxyTemplateUsage>(),
        ObjectCategories: Array.Empty<DashboardGalaxyCategoryCount>());
}

public enum DashboardGalaxyStatus
{
    Unknown = 0,
    Healthy = 1,
    Stale = 2,
    Unavailable = 3,
}

public sealed record DashboardGalaxyTemplateUsage(string TemplateName, int InstanceCount);

public sealed record DashboardGalaxyCategoryCount(int CategoryId, string CategoryName, int ObjectCount);
