using GmRelay.Bot.Features.Sessions.CreateSession;
using GmRelay.Shared.Domain;

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

public sealed class SessionCapacityRulesTests
{
    [Fact]
    public void DecideJoinStatus_ShouldReturnActive_WhenSessionHasFreeSeats()
    {
        var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 3, activeParticipants: 2);

        Assert.Equal(ParticipantRegistrationStatus.Active, status);
    }

    [Fact]
    public void DecideJoinStatus_ShouldReturnWaitlisted_WhenSessionReachedLimit()
    {
        var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 2, activeParticipants: 2);

        Assert.Equal(ParticipantRegistrationStatus.Waitlisted, status);
    }

    [Fact]
    public void CanPromoteWaitlistedPlayer_ShouldRequireWaitlistAndFreeSeat()
    {
        Assert.True(SessionCapacityRules.CanPromoteWaitlistedPlayer(maxPlayers: 3, activeParticipants: 2, waitlistedParticipants: 1));
        Assert.False(SessionCapacityRules.CanPromoteWaitlistedPlayer(maxPlayers: 3, activeParticipants: 3, waitlistedParticipants: 1));
        Assert.False(SessionCapacityRules.CanPromoteWaitlistedPlayer(maxPlayers: 3, activeParticipants: 2, waitlistedParticipants: 0));
    }

    [Fact]
    public void ShouldPromoteAfterParticipantLeaves_ShouldOnlyPromoteAfterActiveParticipantLeaves()
    {
        Assert.True(SessionCapacityRules.ShouldPromoteAfterParticipantLeaves(
            removedRegistrationStatus: ParticipantRegistrationStatus.Active,
            maxPlayers: 2,
            activeParticipantsAfterLeave: 1,
            waitlistedParticipants: 1));

        Assert.False(SessionCapacityRules.ShouldPromoteAfterParticipantLeaves(
            removedRegistrationStatus: ParticipantRegistrationStatus.Waitlisted,
            maxPlayers: 2,
            activeParticipantsAfterLeave: 1,
            waitlistedParticipants: 1));

        Assert.False(SessionCapacityRules.ShouldPromoteAfterParticipantLeaves(
            removedRegistrationStatus: ParticipantRegistrationStatus.Active,
            maxPlayers: 2,
            activeParticipantsAfterLeave: 1,
            waitlistedParticipants: 0));
    }
}
