using System;
using StellaOps.Auth.Client;
using Xunit;

namespace StellaOps.Auth.Client.Tests;

public class StellaOpsAuthClientOptionsTests
{
    [Fact]
    public void Validate_NormalizesScopes()
    {
        var options = new StellaOpsAuthClientOptions
        {
            Authority = "https://authority.test",
            ClientId = "cli",
            HttpTimeout = TimeSpan.FromSeconds(15)
        };
        options.DefaultScopes.Add(" Feedser.Jobs.Trigger ");
        options.DefaultScopes.Add("feedser.jobs.trigger");
        options.DefaultScopes.Add("AUTHORITY.USERS.MANAGE");

        options.Validate();

        Assert.Equal(new[] { "authority.users.manage", "feedser.jobs.trigger" }, options.NormalizedScopes);
        Assert.Equal(new Uri("https://authority.test"), options.AuthorityUri);
    }

    [Fact]
    public void Validate_Throws_When_AuthorityMissing()
    {
        var options = new StellaOpsAuthClientOptions();

        var exception = Assert.Throws<InvalidOperationException>(() => options.Validate());

        Assert.Contains("Authority", exception.Message, StringComparison.OrdinalIgnoreCase);
    }
}
