json([ 'error' => [ 'code' => 'INVALID_CONTEXT', 'message' => 'Invalid narrator context', 'valid_contexts' => self::VALID_CONTEXTS, ], ], 404); } $lang = app()->getLocale(); $heroType = $request->query('hero'); // Valider hero_type if ($heroType && !in_array($heroType, self::VALID_HERO_TYPES)) { $heroType = null; } $narratorText = NarratorText::getRandomText($context, $heroType); if (!$narratorText) { return response()->json([ 'error' => [ 'code' => 'NO_TEXT_FOUND', 'message' => 'No narrator text found for this context', ], ], 404); } $text = Translation::getTranslation($narratorText->text_key, $lang); return response()->json([ 'data' => [ 'context' => $context, 'text' => $text, 'variant' => $narratorText->variant, 'hero_type' => $narratorText->hero_type, ], 'meta' => [ 'lang' => $lang, ], ]); } }