namespace NexusShell.Models;

/// <summary>
/// Future realtime transport — POC uses polling via <see cref="INexusControlCenterPresencePoller"/>.
/// </summary>
public interface INexusControlCenterRealtimeChannel
{
    event EventHandler<NexusControlCenterPresenceSummary>? PresenceUpdated;
    Task ConnectAsync(CancellationToken ct = default);
    Task DisconnectAsync(CancellationToken ct = default);
}

/// <summary>
/// POC polling adapter — replace with SignalR/WebSocket implementation later.
/// </summary>
public interface INexusControlCenterPresencePoller
{
    TimeSpan PollInterval { get; }
    Task<NexusControlCenterPresenceSummary?> PollAsync(CancellationToken ct = default);
}

public sealed class NexusControlCenterPresenceSummary
{
    public DateTime GeneratedAtUtc { get; init; }
    public int OfflineThresholdSeconds { get; init; }
    public int OnlineCount { get; init; }
    public int OfflineCount { get; init; }
    public int WarningCount { get; init; }
    public int CriticalCount { get; init; }
    public IReadOnlyList<NexusControlCenterDevicePresenceRow> Devices { get; init; } = [];
    public string Source { get; init; } = "local";
}

public sealed class NexusControlCenterDevicePresenceRow
{
    public required string DeviceId { get; init; }
    public required string FriendlyName { get; init; }
    public required string Owner { get; init; }
    public required string Organization { get; init; }
    public bool Online { get; init; }
    public required string Health { get; init; }
    public required string AgentVersion { get; init; }
    public required string ShellVersion { get; init; }
    public DateTimeOffset? LastSeen { get; init; }
    public string OnlineLabel => Online ? "Online" : "Offline";
    public string VersionLabel => $"Agent {AgentVersion} · Shell {ShellVersion}";
    public string LastSeenLabel => LastSeen?.ToLocalTime().ToString("g") ?? "—";
}
