using TeleWave.Application.Admin.Users.CreateUser;
using TeleWave.Application.Admin.Users.ResetPassword;
using TeleWave.Application.Broadcast;
using TeleWave.Application.Broadcast.Bumpers;
using TeleWave.Application.Broadcast.UpdateChannelSettings;
using TeleWave.Domain.Broadcast;
using Xunit;

namespace TeleWave.Application.Tests.Validators;

public class ValidatorTests
{
    [Fact]
    public void UpdateBumperTextVariant_ChecksLengthsAndWeight()
    {
        var v = new UpdateBumperTextVariantCommandValidator();

        var good = new UpdateBumperTextVariantCommand(
            Guid.NewGuid(),
            Guid.NewGuid(),
            Guid.NewGuid(),
            "Name",
            BumperTextKind.NowNext,
            "NOW",
            "NEXT",
            "l1",
            "l2",
            BumperTrigger.Both,
            3
        );
        Assert.True(v.Validate(good).IsValid);

        Assert.False(v.Validate(good with { Name = "" }).IsValid);
        Assert.False(v.Validate(good with { Weight = -1 }).IsValid);
        Assert.False(v.Validate(good with { Line1 = new string('x', 121) }).IsValid);
    }

    [Fact]
    public void UpdateChannelSettings_ChecksRanges()
    {
        var v = new UpdateChannelSettingsCommandValidator();
        var bumper = new BumperSettingsInput(BumperFont.Sans, BumperSelection.WeightedRandom);

        var good = new UpdateChannelSettingsCommand(
            Guid.NewGuid(),
            "Name",
            true,
            true,
            bumper,
            null
        );
        Assert.True(v.Validate(good).IsValid);

        Assert.False(v.Validate(good with { Name = "" }).IsValid);
    }

    [Fact]
    public void ResetUserPassword_RequiresMinLength()
    {
        var v = new ResetUserPasswordCommandValidator();

        Assert.True(v.Validate(new ResetUserPasswordCommand(Guid.NewGuid(), "Password1")).IsValid);
        Assert.False(v.Validate(new ResetUserPasswordCommand(Guid.NewGuid(), "short")).IsValid);
        Assert.False(v.Validate(new ResetUserPasswordCommand(Guid.Empty, "Password1")).IsValid);
    }

    [Fact]
    public void CreateUser_ChecksNameAndPassword()
    {
        var v = new CreateUserCommandValidator();

        Assert.True(v.Validate(new CreateUserCommand("bob", "Password1", Guid.NewGuid())).IsValid);
        Assert.False(v.Validate(new CreateUserCommand("ab", "Password1", Guid.NewGuid())).IsValid);
        Assert.False(v.Validate(new CreateUserCommand("bob", "short", Guid.NewGuid())).IsValid);
        Assert.False(v.Validate(new CreateUserCommand("bob", "Password1", Guid.Empty)).IsValid);
    }
}
