using System;
using StellaOps.Authority.Plugin.Standard;

namespace StellaOps.Authority.Plugin.Standard.Tests;

public class StandardPluginOptionsTests
{
    [Fact]
    public void Validate_AllowsBootstrapWhenCredentialsProvided()
    {
        var options = new StandardPluginOptions
        {
            BootstrapUser = new BootstrapUserOptions
            {
                Username = "admin",
                Password = "Bootstrap1!",
                RequirePasswordReset = true
            }
        };

        options.Validate("standard");
    }

    [Fact]
    public void Validate_Throws_WhenBootstrapUserIncomplete()
    {
        var options = new StandardPluginOptions
        {
            BootstrapUser = new BootstrapUserOptions
            {
                Username = "admin",
                Password = null
            }
        };

        var ex = Assert.Throws<InvalidOperationException>(() => options.Validate("standard"));
        Assert.Contains("bootstrapUser", ex.Message, StringComparison.OrdinalIgnoreCase);
    }

    [Fact]
    public void Validate_Throws_WhenLockoutWindowMinutesInvalid()
    {
        var options = new StandardPluginOptions
        {
            Lockout = new LockoutOptions
            {
                Enabled = true,
                MaxAttempts = 5,
                WindowMinutes = 0
            }
        };

        var ex = Assert.Throws<InvalidOperationException>(() => options.Validate("standard"));
        Assert.Contains("lockout.windowMinutes", ex.Message, StringComparison.OrdinalIgnoreCase);
    }
}
