using System.Security.Claims;

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

/// <summary>
/// Result of a dashboard authentication attempt.
/// </summary>
public sealed record DashboardAuthenticationResult(
    /// <summary>
    /// Whether authentication succeeded.
    /// </summary>
    bool Succeeded,
    /// <summary>
    /// The authenticated principal if successful; otherwise null.
    /// </summary>
    ClaimsPrincipal? Principal,
    /// <summary>
    /// The failure message if authentication failed; otherwise null.
    /// </summary>
    string? FailureMessage)
{
    /// <summary>
    /// Creates a successful authentication result.
    /// </summary>
    /// <param name="principal">Authenticated principal.</param>
    /// <returns>A successful <see cref="DashboardAuthenticationResult"/> wrapping <paramref name="principal"/>.</returns>
    public static DashboardAuthenticationResult Success(ClaimsPrincipal principal)
    {
        return new DashboardAuthenticationResult(true, principal, null);
    }

    /// <summary>
    /// Creates a failed authentication result.
    /// </summary>
    /// <param name="failureMessage">Diagnostic message describing the failure.</param>
    /// <returns>A failed <see cref="DashboardAuthenticationResult"/> carrying <paramref name="failureMessage"/>.</returns>
    public static DashboardAuthenticationResult Fail(string failureMessage)
    {
        return new DashboardAuthenticationResult(false, null, failureMessage);
    }
}
