namespace Eis.Infrastructure.Security;

public sealed class DocumentVerificationOptions
{
    private DocumentVerificationOptions(string secret)
    {
        Secret = secret;
    }

    public string Secret { get; }

    internal static DocumentVerificationOptions FromSecret(string secret) => new(secret);

    public static DocumentVerificationOptions FromEnvironment(bool production)
    {
        var configured = Environment.GetEnvironmentVariable("DOCUMENT_VERIFICATION_SECRET") ?? string.Empty;
        if (production && configured.Length < 32)
        {
            throw new InvalidOperationException("生产环境必须设置至少 32 个字符的 DOCUMENT_VERIFICATION_SECRET");
        }

        var secret = configured;
        if (secret.Length == 0)
        {
            secret = Environment.GetEnvironmentVariable("SESSION_SECRET") ?? string.Empty;
        }
        return new DocumentVerificationOptions(
            secret.Length > 0 ? secret : "development-document-verification-secret");
    }
}
