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

/// <summary>
/// Options controlling the gateway's self-signed certificate auto-generation.
/// Only consulted when a Kestrel HTTPS endpoint is configured without its own
/// certificate; plaintext deployments never trigger generation.
/// </summary>
public sealed class TlsOptions
{
    /// <summary>
    /// Path to the persisted self-signed PFX. Reused across restarts. The default is derived
    /// from <see cref="Environment.SpecialFolder.CommonApplicationData"/> (<c>C:\ProgramData</c>
    /// on Windows, <c>/usr/share</c> or the container equivalent elsewhere) so a generated
    /// private key never lands in the launch working directory on a non-Windows host. The
    /// production hosts override this with an explicit path; the validator rejects a non-rooted
    /// override.
    /// </summary>
    public string SelfSignedCertPath { get; init; } = Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
        "MxGateway",
        "certs",
        "gateway-selfsigned.pfx");

    /// <summary>Lifetime in years of a freshly generated certificate.</summary>
    public int ValidityYears { get; init; } = 10;

    /// <summary>Extra DNS SANs to embed (e.g. a load-balancer name).</summary>
    public IReadOnlyList<string> AdditionalDnsNames { get; init; } = [];

    /// <summary>Regenerate the persisted certificate when it has expired.</summary>
    public bool RegenerateIfExpired { get; init; } = true;
}
