using System;
using StellaOps.Authority.Plugins.Abstractions;

namespace StellaOps.Authority.Plugins.Abstractions.Tests;

public class AuthorityCredentialVerificationResultTests
{
    [Fact]
    public void Success_SetsUserAndClearsFailure()
    {
        var user = new AuthorityUserDescriptor("subject-1", "user", "User", false);

        var result = AuthorityCredentialVerificationResult.Success(user, "ok");

        Assert.True(result.Succeeded);
        Assert.Equal(user, result.User);
        Assert.Null(result.FailureCode);
        Assert.Equal("ok", result.Message);
    }

    [Fact]
    public void Success_Throws_WhenUserNull()
    {
        Assert.Throws<ArgumentNullException>(() => AuthorityCredentialVerificationResult.Success(null!));
    }

    [Fact]
    public void Failure_SetsFailureCode()
    {
        var result = AuthorityCredentialVerificationResult.Failure(AuthorityCredentialFailureCode.LockedOut, "locked", TimeSpan.FromMinutes(5));

        Assert.False(result.Succeeded);
        Assert.Null(result.User);
        Assert.Equal(AuthorityCredentialFailureCode.LockedOut, result.FailureCode);
        Assert.Equal("locked", result.Message);
        Assert.Equal(TimeSpan.FromMinutes(5), result.RetryAfter);
    }
}
