has('giro_id')) { $query->where('giro_id', $request->giro_id); } return response()->json($query->get()); } public function store(Request $request): JsonResponse { $validated = $request->validate([ 'metrica' => 'required|string|max:100', 'muy_positivo' => 'nullable|numeric', 'positivo' => 'nullable|numeric', 'neutral' => 'nullable|numeric', 'negativo' => 'nullable|numeric', 'muy_negativo' => 'nullable|numeric', 'giro_id' => 'nullable|exists:giros,id', ]); $umbral = Umbral::create($validated); return response()->json($umbral->load('giro'), 201); } public function show(Umbral $umbral): JsonResponse { return response()->json($umbral->load('giro')); } public function update(Request $request, Umbral $umbral): JsonResponse { $validated = $request->validate([ 'metrica' => 'string|max:100', 'muy_positivo' => 'nullable|numeric', 'positivo' => 'nullable|numeric', 'neutral' => 'nullable|numeric', 'negativo' => 'nullable|numeric', 'muy_negativo' => 'nullable|numeric', 'giro_id' => 'nullable|exists:giros,id', ]); $umbral->update($validated); return response()->json($umbral->load('giro')); } public function destroy(Umbral $umbral): JsonResponse { $umbral->delete(); return response()->json(['message' => 'Umbral eliminado']); } public function porMetrica(string $metrica, ?int $giroId = null): JsonResponse { // Buscar primero umbral específico del giro, luego el genérico $umbral = Umbral::where('metrica', $metrica) ->where('giro_id', $giroId) ->first(); if (!$umbral) { $umbral = Umbral::where('metrica', $metrica) ->whereNull('giro_id') ->first(); } if (!$umbral) { return response()->json(['message' => 'Umbral no encontrado'], 404); } return response()->json($umbral); } }