using Koogle.Application.Games; using Koogle.Domain.Enums; namespace Koogle.Web.Store.GameState; // Game Lifecycle Actions /// /// Action to start a new game. /// public record StartGameAction( Guid DayId, string GameTypeName, Guid[] PlayerIds, ThrowMode ThrowMode, int ThrowsPerRound, ParticipantsMode ParticipantsMode, object? InitialGameModel, IGameSetupModel? Setup); /// /// Action dispatched when game is started successfully. /// public record StartGameSuccessAction( Guid GameId, string GameTypeName, ThrowPanelState ThrowPanel, ParticipantsState Participants, object? GameModel, IGameSetupModel? Setup); /// /// Action dispatched when starting game fails. /// public record StartGameFailureAction(string Error); /// /// Action to end the current game. /// /// Final game status. /// Optional winner ID. /// Optional winner display name. /// Optional final scores per player. public record EndGameAction( GameStatus FinalStatus = GameStatus.Completed, Guid? WinnerId = null, string? WinnerName = null, Dictionary? FinalScores = null); /// /// Action dispatched when game is ended successfully. /// public record EndGameSuccessAction(GameSummaryDto Summary); /// /// Action dispatched when ending game fails. /// public record EndGameFailureAction(string Error); /// /// Action to load an active game from database (recovery). /// public record LoadActiveGameAction(Guid DayId); /// /// Action dispatched when active game is loaded successfully. /// public record LoadActiveGameSuccessAction( Guid GameId, string GameTypeName, ThrowPanelState ThrowPanelBefore, ThrowPanelState ThrowPanelAfter, ParticipantsState Participants, object? GameModel, IReadOnlyList UndoStack, IReadOnlyList RedoStack, IGameSetupModel? Setup); /// /// Action dispatched when no active game exists. /// public record NoActiveGameAction; /// /// Action dispatched when loading active game fails. /// public record LoadActiveGameFailureAction(string Error); /// /// Action to load completed games for a day. /// public record LoadCompletedGamesAction(Guid DayId); /// /// Action dispatched when completed games are loaded successfully. /// public record LoadCompletedGamesSuccessAction(IReadOnlyList Games); /// /// Action dispatched when loading completed games fails. /// public record LoadCompletedGamesFailureAction(string Error); // Throw Actions /// /// Action to record a throw with pin results. /// /// State before the throw was made. /// State after the throw was made. /// Whether the throw went into the gutter. /// Whether it was the left gutter. public record RecordThrowAction(ThrowPanelState BeforeThrowState, ThrowPanelState AfterThrowState, bool IsGutter = false, bool IsLeftGutter = false); /// /// Action dispatched after ProcessThrow completes with game logic result. /// /// Updated throw panel state. /// Updated game model from ProcessThrow. /// Whether to rotate to next player. /// Override: specific player to set as current. /// Override: custom pin pattern for next throw. /// Whether the game has ended. /// Winner if game is over. public record ProcessThrowResultAction( ThrowPanelState NewThrowPanelState, object? UpdatedGameModel, bool ShouldRotatePlayer, Guid? NextPlayerId, PinStatus[]? PinPattern, bool IsGameOver, Guid? WinnerId); /// /// Action dispatched when throw is recorded successfully. /// public record RecordThrowSuccessAction; /// /// Action dispatched when recording throw fails. /// public record RecordThrowFailureAction(string Error); /// /// Action to set a single pin status. /// public record SetPinStatusAction(int PinNumber, PinStatus Status); /// /// Action to reset all pins to standing. /// public record ResetPinsAction; /// /// Action to set the bell value. /// public record SetBellValueAction(bool Value); // Player Actions /// /// Action to advance to the next player. /// public record NextPlayerAction; /// /// Action to set the current player. /// public record SetCurrentPlayerAction(Guid PlayerId); // Undo Actions /// /// Action to undo the last throw. /// public record UndoThrowAction; /// /// Action dispatched when undo is successful. /// public record UndoThrowSuccessAction( ThrowPanelState ThrowPanel, ParticipantsState Participants, object? GameModel, bool IsSaving); /// /// Action dispatched when undo fails (e.g., empty stack). /// public record UndoThrowFailureAction(string Error); // Redo Actions /// /// Action to redo a previously undone throw. /// public record RedoThrowAction; /// /// Action dispatched when redo is successful. /// public record RedoThrowSuccessAction( ThrowPanelState ThrowPanel, ParticipantsState Participants, object? GameModel, bool IsSaving); /// /// Action dispatched when redo fails (e.g., empty stack). /// public record RedoThrowFailureAction(string Error); // Persistence Actions /// /// Action to save current game state to database. /// public record SaveGameStateAction; /// /// Action dispatched when game state is saved successfully. /// public record SaveGameStateSuccessAction; /// /// Action dispatched when saving game state fails. /// public record SaveGameStateFailureAction(string Error); /// /// Action dispatched when a concurrency conflict occurs. /// public record ConcurrencyConflictAction(Guid GameId); /// /// Action to clear the concurrency conflict flag. /// public record ClearConcurrencyConflictAction; // SignalR Actions /// /// Action dispatched when game state update is received from SignalR. /// public record GameStateUpdatedFromHubAction( ThrowPanelState ThrowPanel, ParticipantsState Participants, object? GameModel); /// /// Action dispatched when game ended notification is received from SignalR. /// public record GameEndedFromHubAction(GameSummaryDto Summary); // Error Actions /// /// Action to clear game error state. /// public record ClearGameErrorAction; // Game Model Update Action /// /// Action to update the game-specific model. /// public record UpdateGameModelAction(object? GameModel);