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

namespace StellaOps.Authority.Plugins.Abstractions.Tests;

public class AuthorityPluginOperationResultTests
{
    [Fact]
    public void Success_ReturnsSucceededResult()
    {
        var result = AuthorityPluginOperationResult.Success("ok");

        Assert.True(result.Succeeded);
        Assert.Null(result.ErrorCode);
        Assert.Equal("ok", result.Message);
    }

    [Fact]
    public void Failure_PopulatesErrorCode()
    {
        var result = AuthorityPluginOperationResult.Failure("ERR_CODE", "failure");

        Assert.False(result.Succeeded);
        Assert.Equal("ERR_CODE", result.ErrorCode);
        Assert.Equal("failure", result.Message);
    }

    [Fact]
    public void Failure_Throws_WhenErrorCodeMissing()
    {
        Assert.Throws<ArgumentException>(() => AuthorityPluginOperationResult.Failure(string.Empty));
    }

    [Fact]
    public void GenericSuccess_ReturnsValue()
    {
        var result = AuthorityPluginOperationResult<string>.Success("value", "created");

        Assert.True(result.Succeeded);
        Assert.Equal("value", result.Value);
        Assert.Equal("created", result.Message);
    }

    [Fact]
    public void GenericFailure_PopulatesErrorCode()
    {
        var result = AuthorityPluginOperationResult<int>.Failure("CONFLICT", "duplicate");

        Assert.False(result.Succeeded);
        Assert.Equal(default, result.Value);
        Assert.Equal("CONFLICT", result.ErrorCode);
        Assert.Equal("duplicate", result.Message);
    }

    [Fact]
    public void GenericFailure_Throws_WhenErrorCodeMissing()
    {
        Assert.Throws<ArgumentException>(() => AuthorityPluginOperationResult<string>.Failure(" "));
    }
}
