using Arch.Core;
using HSchool.Schedule;
using HSchool.Simulation;
namespace HSchool.Server.Game;
///
/// Live slice of one school for a diagnostic dump. Built on the worker thread; HTTP never sees
/// the World.
///
internal sealed record SchoolLiveDump(
DateTime GameTime,
bool Running,
IReadOnlyList Presence,
IReadOnlyDictionary> Needs,
IReadOnlyList Now);
/// Reads presence and needs from the live school. Call only on that school's worker.
internal static class SchoolDumpReader
{
private static readonly QueryDescription IdentityAndNeeds =
new QueryDescription().WithAll();
public static SchoolLiveDump Read(School school, int weekDays)
{
var needs = new Dictionary>(StringComparer.Ordinal);
school.World.Query(in IdentityAndNeeds, (ref PersonIdentity identity, ref PersonNeeds live) =>
{
needs[identity.Id] = new Dictionary(live.Values, StringComparer.Ordinal);
});
IReadOnlyList now = [];
if (school.Timetable is not null && school.Catalog is not null)
{
now = TimetableClock.OccurringAt(school.Timetable, school.Catalog, school.Clock.Time, weekDays);
}
return new SchoolLiveDump(
school.Clock.Time,
school.Clock.IsRunning,
school.CapturePresence(),
needs,
now);
}
}