using adas_core.Domain.Models.MongoModels;

namespace adas_core.Domain.Models.AppSettings;

public class AuthSettings
{
    public JwtConfig? JwtConfig { get; set; }
    public UsersWhiteListConfig UsersWhiteListConfig { get; set; } = [];
    public List<string> LoginMethods { get; set; } = [];
}

public class JwtConfig : JwtExtConfig
{
    public string? Issuer { get; set; }
    public bool ValidateIssuer { get; set; } = true;

    public int TokenValidityInMinutes { get; set; } = 10;
    public int RefreshTokenValidityInMinutes { get; set; } = 1440;

    public Dictionary<string, JwtExtConfig>? ExternalProviders { get; set; } = null;
}

public class JwtExtConfig
{
    public string? Key { get; set; }
    public string? Audience { get; set; }
    public bool ValidateAudience { get; set; } = true;
}

public class UsersWhiteListConfig : List<string>
{
    public bool IsValid(User user)
    {
        return this.Any(username => username.ToLowerInvariant().Equals(user.UserName.ToLowerInvariant()));
    }
}

public class ValidGroupsConfig : List<ValidGroup>
{
    public bool IsValid(User? user)
    {
        return user != null;
    }
}

public class ValidGroup
{
    public string? Name { get; set; }
    public bool IsRegex { get; set; } = false;
}