using HSchool.Content;
using HSchool.People;
using HSchool.Server.Api;
using HSchool.Simulation;
namespace HSchool.Server.Game;
///
/// Work item handed from a request or connection thread to the supervisor. Create, delete and
/// name suggestions stay here; open/close/running/speed/skip are forwarded to the school's worker.
///
internal abstract record GameCommand
{
internal sealed record CreateSchool(
string Name,
DateTime StartDate,
IReadOnlyList? ExtraModIds,
MapLayout? Map,
string? CountryId,
string? NativeLanguage,
int? Seed,
TaskCompletionSource Result) : GameCommand;
internal sealed record DeleteSchool(int SchoolId, TaskCompletionSource Result) : GameCommand;
internal sealed record SuggestName(SchoolNameLanguage Language, TaskCompletionSource Result) : GameCommand;
/// A connection starts watching a school; clock frames follow from that worker.
internal sealed record OpenSchool(uint PlayerId, int SchoolId) : GameCommand;
///
/// Stops watching. The school id travels with the command because the connection may already
/// be gone from the registry by the time the supervisor gets here.
///
internal sealed record CloseSchool(uint PlayerId, int SchoolId) : GameCommand;
internal sealed record SetRunning(uint PlayerId, bool Running) : GameCommand;
internal sealed record SetSpeed(uint PlayerId, byte SpeedIndex) : GameCommand;
internal sealed record SkipEmpty(uint PlayerId) : GameCommand;
/// Stops every worker, re-reads the save directory, starts workers from those files.
internal sealed record ReloadSaves(TaskCompletionSource Result) : GameCommand;
///
/// A worker thread ended on an exception. The supervisor owns the table, so the worker asks
/// it to drop the school instead of removing itself.
///
internal sealed record WorkerFailed(int SchoolId) : GameCommand;
/// Live presence and needs for a diagnostic dump. Completes on that school's worker.
internal sealed record DumpSchool(int SchoolId, TaskCompletionSource Result) : GameCommand;
/// One person's card, including live needs. Completes on that school's worker thread.
internal sealed record GetPerson(
int SchoolId,
string PersonId,
string Locale,
TaskCompletionSource Result) : GameCommand;
internal sealed record HireStaff(
int SchoolId,
string PersonId,
string Position,
TaskCompletionSource Result) : GameCommand;
internal sealed record AssignSubject(
int SchoolId,
string PersonId,
string Subject,
TaskCompletionSource Result) : GameCommand;
internal sealed record UnassignSubject(
int SchoolId,
string PersonId,
string Subject,
TaskCompletionSource Result) : GameCommand;
internal sealed record PinLesson(
int SchoolId,
string ClassId,
string Subject,
string RoomId,
int Day,
int Period,
TaskCompletionSource Result) : GameCommand;
internal sealed record UnpinLesson(
int SchoolId,
string ClassId,
string Subject,
int Day,
int Period,
TaskCompletionSource Result) : GameCommand;
}