package handlers import ( "net/http" "galaxy/gamemaster/internal/domain/operation" "galaxy/gamemaster/internal/service/adminforce" ) // newForceNextTurnHandler returns the handler for // `POST /api/v1/internal/runtimes/{game_id}/force-next-turn`. The // request has no body; the handler delegates to // `adminforce.Service.Handle` and encodes the resulting runtime // record on success. func newForceNextTurnHandler(deps Dependencies) http.HandlerFunc { logger := loggerFor(deps.Logger, "internal_rest.force_next_turn") return func(writer http.ResponseWriter, request *http.Request) { if deps.ForceNextTurn == nil { writeError(writer, http.StatusInternalServerError, errorCodeInternal, "force next turn service is not wired") return } gameID, ok := extractGameID(writer, request) if !ok { return } result, err := deps.ForceNextTurn.Handle(request.Context(), adminforce.Input{ GameID: gameID, OpSource: resolveOpSource(request), SourceRef: requestSourceRef(request), }) if err != nil { logger.ErrorContext(request.Context(), "force next turn service errored", "game_id", gameID, "err", err.Error(), ) writeError(writer, http.StatusInternalServerError, errorCodeInternal, "force next turn service failed") return } if result.Outcome == operation.OutcomeFailure { writeFailure(writer, result.ErrorCode, result.ErrorMessage) return } writeJSON(writer, http.StatusOK, encodeRuntimeRecord(result.TurnGeneration.Record)) } }