using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Timetables;

namespace Jiaowu.Api.Tests;

public sealed class FreeClassroomRulesTests
{
    [Theory]
    [InlineData(WeekPattern.All, 2, true)]
    [InlineData(WeekPattern.Odd, 3, true)]
    [InlineData(WeekPattern.Odd, 4, false)]
    [InlineData(WeekPattern.Even, 4, true)]
    [InlineData(WeekPattern.Even, 3, false)]
    public void MatchesWeek_respects_all_odd_and_even_patterns(
        WeekPattern pattern,
        int week,
        bool expected)
    {
        Assert.Equal(expected, FreeClassroomRules.MatchesWeek(pattern, week));
    }

    [Theory]
    [InlineData(1, 2, 2, 2, true)]
    [InlineData(3, 1, 2, 1, false)]
    [InlineData(1, 1, 2, 1, false)]
    [InlineData(4, 3, 3, 5, true)]
    public void PeriodsOverlap_uses_half_open_period_ranges(
        int requestedStart,
        int requestedCount,
        int occupiedStart,
        int occupiedCount,
        bool expected)
    {
        Assert.Equal(expected, FreeClassroomRules.PeriodsOverlap(
            requestedStart,
            requestedCount,
            occupiedStart,
            occupiedCount));
    }
}
