using ZB.MOM.WW.Secrets.Abstractions;

namespace ZB.MOM.WW.Secrets.Cli.Interactive;

/// <summary>An open store session for one target. Degraded when no KEK is available (metadata ops only).</summary>
public sealed class SecretsSession
{
    /// <summary>The target this session operates on.</summary>
    public required StoreTarget Target { get; init; }

    /// <summary>The store backing this session (SQLite or SQL Server).</summary>
    public required ISecretStore Store { get; init; }

    /// <summary>The migrator matching <see cref="Store"/>; already run once when the session was opened.</summary>
    public required ISecretsStoreMigrator Migrator { get; init; }

    /// <summary>The resolved master-key provider, or <see langword="null"/> when the session is degraded.</summary>
    public IMasterKeyProvider? MasterKey { get; init; }

    /// <summary>The envelope cipher, or <see langword="null"/> when the session is degraded (no KEK).</summary>
    public ISecretCipher? Cipher { get; init; }

    /// <summary>The concrete store kind: <c>"sqlite"</c> or <c>"sqlserver"</c>.</summary>
    public required string StoreKind { get; init; }

    /// <summary>Non-fatal warnings raised while opening (KEK unavailable, store fall-back, and so on).</summary>
    public IReadOnlyList<string> Warnings { get; init; } = [];

    /// <summary>Whether a KEK (and therefore a cipher) is available — <see langword="false"/> in degraded mode.</summary>
    public bool KekAvailable => Cipher is not null;
}
