namespace NucleicBroker;

/// <summary>
/// The facade used when Microsoft.WSL.Containers isn't compiled in (any non-Windows build,
/// or a build without -p:UseWslc=true): every operation fails with a structured
/// `wslc_unavailable` error so hostd sees a clean capability gap, never a crash. The `hello`
/// exchange reports `wslcVersion: null`, which is the real capability signal.
/// </summary>
public sealed class UnavailableWslc : IWslc
{
    public string? WslcVersion => null;

    /// Nothing bound, so nothing is capable — the empty list IS the capability report.
    public IReadOnlyList<string> Capabilities => [];

    public void SetEvents(IBrokerEvents events) { }

    private static WslcError Unavailable() =>
        new(WslcError.Unavailable, "Microsoft.WSL.Containers is not available in this broker build");

    public Task<IReadOnlyList<string>> MissingComponentsAsync(CancellationToken ct) =>
        Task.FromException<IReadOnlyList<string>>(Unavailable());
    public Task InstallComponentsAsync(CancellationToken ct) => Task.FromException(Unavailable());
    public Task<string> EnsureSessionAsync(SessionSpec spec, CancellationToken ct) =>
        Task.FromException<string>(Unavailable());
    public Task TerminateSessionAsync(CancellationToken ct) => Task.FromException(Unavailable());
    public Task PullImageAsync(string reference, RegistryAuth? auth, CancellationToken ct) =>
        Task.FromException(Unavailable());
    public Task<IReadOnlyList<ImageInfo>> ListImagesAsync(CancellationToken ct) =>
        Task.FromException<IReadOnlyList<ImageInfo>>(Unavailable());
    public Task DeleteImageAsync(string reference, CancellationToken ct) =>
        Task.FromException(Unavailable());
    public Task<ImageInfo?> InspectImageAsync(string reference, CancellationToken ct) =>
        Task.FromException<ImageInfo?>(Unavailable());
    public Task CreateContainerAsync(ContainerCreateSpec spec, CancellationToken ct) =>
        Task.FromException(Unavailable());
    public Task StartContainerAsync(string name, CancellationToken ct) =>
        Task.FromException(Unavailable());
    public Task StopContainerAsync(string name, int signal, int graceMs, CancellationToken ct) =>
        Task.FromException(Unavailable());
    public Task DeleteContainerAsync(string name, bool force, CancellationToken ct) =>
        Task.FromException(Unavailable());
    public Task<IReadOnlyList<ContainerInfo>> ListContainersAsync(CancellationToken ct) =>
        Task.FromException<IReadOnlyList<ContainerInfo>>(Unavailable());
    public Task<string> ContainerStateAsync(string name, CancellationToken ct) =>
        Task.FromException<string>(Unavailable());
    public Task<ContainerStatsInfo?> ContainerStatsAsync(string name, CancellationToken ct) =>
        Task.FromException<ContainerStatsInfo?>(Unavailable());
    public Task<IWslcProcess> ExecAsync(long procId, ProcSpec spec, CancellationToken ct) =>
        Task.FromException<IWslcProcess>(Unavailable());
}
