using System.Security.Claims;

namespace Ablera.Serdica.Authority.Plugins.Base.Models;

public enum AuthenticationCode
{
    GenericError,
    AccountIsNotFound,
    AccountIsLocked,
    AccountIsNotActive,
    EmptyCredentials,
    InvalidPassword,
    NoAuthBackend,
    ClientIsUnknown,
    ClientWithNoSecretDoesNotMatchAllowedMask,
    ClientSecretIsInvalid,
    InvalidCredentials,
    AccountIsNotAuthenticaAble
}


/// <summary>
/// Result of an authentication attempt. Use the static helpers for convenience.
/// </summary>
public sealed class AuthenticationResult
{
    private AuthenticationResult(bool succeeded, string? errorCode, ClaimsPrincipal? claimsPrincipal)
    {
        Succeeded = succeeded;
        ErrorCode = errorCode;
        ClaimsPrincipal = claimsPrincipal;
    }

    public bool Succeeded { get; }
    public string? ErrorCode { get; }
    public ClaimsPrincipal? ClaimsPrincipal { get; }

    public static AuthenticationResult Success(ClaimsPrincipal? claimsPrincipal) =>
        new AuthenticationResult(true, null, claimsPrincipal);

    public static AuthenticationResult Fail(string errorCode) =>
        new AuthenticationResult(false, errorCode, null);
}
