using NATS.Server.Auth;

namespace NATS.Server.Imports;

public sealed class ExportAuth
{
    public bool TokenRequired { get; init; }
    public uint AccountPosition { get; init; }
    public HashSet<string>? ApprovedAccounts { get; init; }
    public Dictionary<string, long>? RevokedAccounts { get; init; }

    public bool IsAuthorized(Account account)
    {
        if (RevokedAccounts != null && RevokedAccounts.ContainsKey(account.Name))
            return false;

        if (ApprovedAccounts == null && !TokenRequired && AccountPosition == 0)
            return true;

        if (ApprovedAccounts != null)
            return ApprovedAccounts.Contains(account.Name);

        return false;
    }
}
