alarmService = $alarmService; } public function createOrUpdateAlarm(Request $request) { try { $alarmData = [ 'type' => $request->type ?? null, 'severity' => $request->severity ?? null, 'acknowledged' => false ?? null, 'cleared' => $request->cleared ?? Carbon::now()->timestamp, 'startTs' => $request->startTs ?? Carbon::now()->timestamp, 'endTs' => $request->endTs ?? Carbon::now()->timestamp, 'details' => $request->details ?? [], 'propagate' => $request->propagate ?? false, 'propagateToOwner' => $request->propagateToOwner ?? false, 'propagateToTenant' => $request->propagateToTenant ?? false, 'originator' => $request->originator ?? 1, 'assigneeId' => $request->assigneeId ?? 1, ]; // Handle updating existing alarm if (!empty($request->id)) { $alarmData['id'] = $request->id; } // Call Service to create/update device $apiResponse = $this->alarmService->createOrUpdateAlarm($alarmData); return jsonResponseWithSuccessMessage( !empty($request->id) ? 'Alarm updated successfully' : 'Alarm created successfully', ['api_response' => $apiResponse] ); } catch (Exception $e) { Log::error("Error: " . $e->getMessage()); $errorResponse = json_decode($e->getMessage(), true); if (json_last_error() === JSON_ERROR_NONE) { return jsonResponseWithErrorMessage($errorResponse['message'] ?? 'Something went wrong', 400, $errorResponse); } return jsonResponseWithErrorMessage($e->getMessage(), 500); } } }