currentService->listCurrent(); return response()->json([ 'ok' => true, 'incidents' => IncidentResource::collection($data['incidents']), 'grades' => IncidentGradeResource::collection($data['grades']), ]); } public function history(IncidentListRequest $request): JsonResponse { $payload = $request->validated(); $incidents = $this->historyService->history($payload['school_year'] ?? null, $payload['semester'] ?? null); return response()->json([ 'ok' => true, 'incidents' => IncidentResource::collection($incidents), ]); } public function processed(IncidentListRequest $request): JsonResponse { $payload = $request->validated(); $incidents = $this->historyService->processed($payload['school_year'] ?? null, $payload['semester'] ?? null); return response()->json([ 'ok' => true, 'incidents' => IncidentResource::collection($incidents), ]); } public function analysis(IncidentListRequest $request): JsonResponse { $payload = $request->validated(); $students = $this->analysisService->analyze($payload['school_year'] ?? null, $payload['semester'] ?? null); return response()->json([ 'ok' => true, 'students' => IncidentAnalysisStudentResource::collection($students), 'school_year' => $payload['school_year'] ?? null, 'semester' => $payload['semester'] ?? null, ]); } public function studentsByGrade(int $gradeId): JsonResponse { $students = $this->currentService->studentsByGrade($gradeId); return response()->json([ 'ok' => true, 'students' => IncidentStudentOptionResource::collection($students), ]); } public function store(IncidentStoreRequest $request): JsonResponse { $payload = $request->validated(); $result = $this->currentService->addIncident($payload, (int) (auth()->id() ?? 0)); if (empty($result['ok'])) { return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to add incident.'], 422); } return response()->json([ 'ok' => true, 'created' => $result['created'], 'incident_id' => $result['incident_id'], ]); } public function updateState(IncidentStateRequest $request, int $incidentId): JsonResponse { $payload = $request->validated(); $updated = $this->currentService->updateState($incidentId, (string) $payload['incident_state']); return response()->json([ 'ok' => $updated, ]); } public function close(IncidentCloseRequest $request, int $incidentId): JsonResponse { $payload = $request->validated(); $result = $this->currentService->closeIncident( $incidentId, (string) $payload['state_description'], $payload['action_taken'] ?? null, (int) (auth()->id() ?? 0) ); if (empty($result['ok'])) { return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to close incident.'], 422); } return response()->json([ 'ok' => true, 'incident_id' => $result['incident_id'], ]); } public function cancel(IncidentCancelRequest $request, int $incidentId): JsonResponse { $payload = $request->validated(); $result = $this->currentService->cancelIncident( $incidentId, $payload['state_description'] ?? null, $payload['action_taken'] ?? null, (int) (auth()->id() ?? 0) ); if (empty($result['ok'])) { return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to cancel incident.'], 422); } return response()->json([ 'ok' => true, 'incident_id' => $result['incident_id'], ]); } }