using HSchool.Content;
namespace HSchool.Schedule;
///
/// Which lessons are happening at a game instant. Breaks, nights, weekends and holidays are empty
/// — occupancy is derived, never stored.
///
public static class TimetableClock
{
public static IReadOnlyList OccurringAt(
Timetable table,
DefCatalog catalog,
DateTime time,
int weekDays)
{
ArgumentNullException.ThrowIfNull(table);
var slot = SchoolDay.At(catalog, time, weekDays);
if (slot.Kind != DaySlotKind.Lesson)
{
return [];
}
var day = SchoolDay.WeekdayIndex(time);
return table.Lessons
.Where(lesson => lesson.Day == day && lesson.Period == slot.Index)
.ToArray();
}
public static OccupancyKey Key(DefCatalog catalog, DateTime time, int weekDays)
{
var utc = DateTime.SpecifyKind(time, DateTimeKind.Utc);
var slot = SchoolDay.At(catalog, utc, weekDays);
return new OccupancyKey(DateOnly.FromDateTime(utc), slot.Kind, slot.Index);
}
}
public readonly record struct OccupancyKey(DateOnly Day, DaySlotKind Kind, int Index);