using TeleWave.Domain.Broadcast;
using Xunit;

namespace TeleWave.Domain.Tests.Broadcast;

public class BumperTextVariantTests
{
    private static BumperTextVariant NewVariant() =>
        Channel
            .Create("c", "c", DateTimeOffset.UnixEpoch)
            .AddBumperTemplate("b")
            .AddVariant("Text");

    [Fact]
    public void Create_HasDefaultLabelsAndWeight()
    {
        var v = NewVariant();

        Assert.Equal(BumperTextKind.NowNext, v.Kind);
        Assert.Equal(BumperTextVariant.DefaultNowLabel, v.NowLabel);
        Assert.Equal(BumperTextVariant.DefaultNextLabel, v.NextLabel);
        Assert.Equal(BumperTextVariant.DefaultWeight, v.Weight);
        Assert.Equal(string.Empty, v.Line1);
    }

    [Fact]
    public void Update_SetsFields_AndClampsNegativeWeightToZero()
    {
        var v = NewVariant();

        v.Update(
            "Name",
            new BumperTextContent(BumperTextKind.Free, "NOW", "NEXT", "l1", "l2"),
            BumperTrigger.Both,
            -5
        );

        Assert.Equal("Name", v.Name);
        Assert.Equal(BumperTextKind.Free, v.Kind);
        Assert.Equal("NOW", v.NowLabel);
        Assert.Equal("l1", v.Line1);
        Assert.Equal(BumperTrigger.Both, v.Trigger);
        Assert.Equal(0, v.Weight);
    }

    [Theory]
    [InlineData(BumperTrigger.OnShowChange, true, true)]
    [InlineData(BumperTrigger.OnShowChange, false, false)]
    [InlineData(BumperTrigger.BetweenEpisodes, true, false)]
    [InlineData(BumperTrigger.BetweenEpisodes, false, true)]
    [InlineData(BumperTrigger.Both, true, true)]
    [InlineData(BumperTrigger.Both, false, true)]
    public void Matches_FollowsTrigger(BumperTrigger trigger, bool isShowChange, bool expected)
    {
        var v = NewVariant();
        v.Update("n", new BumperTextContent(BumperTextKind.NowNext, "a", "b", "", ""), trigger, 1);

        Assert.Equal(expected, v.Matches(isShowChange));
    }
}
