using GmRelay.Bot.Features.Sessions.RescheduleSession;

namespace GmRelay.Bot.Tests.Features.Sessions.RescheduleSession;

public sealed class RescheduleVoteRulesTests
{
    [Fact]
    public void SelectWinner_ShouldApproveSingleTopOption()
    {
        var winningOptionId = Guid.NewGuid();
        var otherOptionId = Guid.NewGuid();

        var decision = RescheduleVoteRules.SelectWinner(
            [
                new RescheduleOptionVoteCount(winningOptionId, 3),
                new RescheduleOptionVoteCount(otherOptionId, 1)
            ]);

        Assert.Equal(RescheduleVoteOutcome.Approved, decision.Outcome);
        Assert.Equal(winningOptionId, decision.SelectedOptionId);
        Assert.Equal("Победил вариант с большинством голосов.", decision.Reason);
    }

    [Fact]
    public void SelectWinner_ShouldRejectTie()
    {
        var firstOptionId = Guid.NewGuid();
        var secondOptionId = Guid.NewGuid();

        var decision = RescheduleVoteRules.SelectWinner(
            [
                new RescheduleOptionVoteCount(firstOptionId, 2),
                new RescheduleOptionVoteCount(secondOptionId, 2)
            ]);

        Assert.Equal(RescheduleVoteOutcome.Rejected, decision.Outcome);
        Assert.Null(decision.SelectedOptionId);
        Assert.Equal("Голоса разделились поровну, перенос не применяется.", decision.Reason);
    }

    [Fact]
    public void SelectWinner_ShouldRejectWhenNobodyVoted()
    {
        var decision = RescheduleVoteRules.SelectWinner(
            [
                new RescheduleOptionVoteCount(Guid.NewGuid(), 0),
                new RescheduleOptionVoteCount(Guid.NewGuid(), 0)
            ]);

        Assert.Equal(RescheduleVoteOutcome.Rejected, decision.Outcome);
        Assert.Null(decision.SelectedOptionId);
        Assert.Equal("Никто не проголосовал до дедлайна, перенос не применяется.", decision.Reason);
    }
}
