using Microsoft.IdentityModel.Tokens;

namespace StellaOps.Scanner.Core.Security;

public sealed class DpopValidationResult
{
    private DpopValidationResult(bool success, string? errorCode, string? errorDescription, SecurityKey? key, string? jwtId, DateTimeOffset? issuedAt)
    {
        IsValid = success;
        ErrorCode = errorCode;
        ErrorDescription = errorDescription;
        PublicKey = key;
        JwtId = jwtId;
        IssuedAt = issuedAt;
    }

    public bool IsValid { get; }

    public string? ErrorCode { get; }

    public string? ErrorDescription { get; }

    public SecurityKey? PublicKey { get; }

    public string? JwtId { get; }

    public DateTimeOffset? IssuedAt { get; }

    public static DpopValidationResult Success(SecurityKey key, string jwtId, DateTimeOffset issuedAt)
        => new(true, null, null, key, jwtId, issuedAt);

    public static DpopValidationResult Failure(string code, string description)
        => new(false, code, description, null, null, null);
}
