namespace NexusShell.Models;

/// <summary>
/// In-progress deployment phases for a package (stable states remain in <see cref="NexusPackageState"/>).
/// </summary>
public enum NexusDeploymentPhase
{
    None,
    Downloading,
    Installing,
    Updating,
    Removing,
    Failed,
}

public enum NexusDeploymentOperation
{
    Install,
    Update,
    Remove,
}

public sealed class NexusDeploymentProgress
{
    public required string PackageId { get; init; }
    public NexusDeploymentOperation Operation { get; init; }
    public NexusDeploymentPhase Phase { get; init; }
    public string Message { get; init; } = string.Empty;
    public double Percent { get; init; }
}

public sealed class NexusDeploymentResult
{
    public required string PackageId { get; init; }
    public bool Success { get; init; }
    public string? InstalledVersion { get; init; }
    public string? Message { get; init; }
}

/// <summary>
/// Future update capabilities — design stubs only in Deployment Engine 1.0 POC.
/// </summary>
public interface INexusPackageDeltaUpdater
{
    /// <summary>Apply a binary delta patch instead of a full .nxp replace (not implemented).</summary>
    Task<bool> ApplyDeltaAsync(string packageId, string deltaPath, CancellationToken cancellationToken = default);
}

public sealed class NexusPackageDeltaUpdaterStub : INexusPackageDeltaUpdater
{
    public Task<bool> ApplyDeltaAsync(string packageId, string deltaPath, CancellationToken cancellationToken = default) =>
        Task.FromResult(false);
}

public interface INexusMandatoryUpdatePolicy
{
    bool IsMandatory(NexusPackageManifest manifest, string? installedVersion);
    bool ShouldBlockLaunch(NexusPackageManifest manifest, string? installedVersion);
}

public sealed class NexusMandatoryUpdatePolicyStub : INexusMandatoryUpdatePolicy
{
    public bool IsMandatory(NexusPackageManifest manifest, string? installedVersion) =>
        !string.IsNullOrWhiteSpace(manifest.MinNexusVersion) &&
        !string.IsNullOrWhiteSpace(installedVersion);

    public bool ShouldBlockLaunch(NexusPackageManifest manifest, string? installedVersion) => false;
}

public interface INexusDependencyUpdateCoordinator
{
    IReadOnlyList<string> GetPackagesRequiringUpdate(IEnumerable<string> updatedPackageIds);
    Task<bool> QueueDependencyUpdatesAsync(IEnumerable<string> packageIds, CancellationToken cancellationToken = default);
}

public sealed class NexusDependencyUpdateCoordinatorStub : INexusDependencyUpdateCoordinator
{
    public IReadOnlyList<string> GetPackagesRequiringUpdate(IEnumerable<string> updatedPackageIds) => [];

    public Task<bool> QueueDependencyUpdatesAsync(IEnumerable<string> packageIds, CancellationToken cancellationToken = default) =>
        Task.FromResult(false);
}
