userModel = new UserModel(); $this->interactionDetailsModel = new InteractionDetailsModel(); } public function __invoke(ServerRequestInterface $request) { $userId = (int) ($request->getAttribute('user_id') ?? 0); $conversationId = (int) (($request->getQueryParams()['conversation_id'] ?? 0)); if ($userId <= 0) { return Payload::fail('Unauthorized: Missing authenticated user', [], 'E_VALIDATE', 401); } if ($conversationId <= 0) { return Payload::fail('Missing or invalid conversation_id', [], 'E_VALIDATE', 400); } try { $companyId = $this->userModel->getCompanyIdByUserId($userId); if ($companyId === null) { return Payload::fail('User not found', [], 'E_NOT_FOUND', 404); } $data = $this->interactionDetailsModel->getInteractionDetails($companyId, $conversationId); if ($data === null) { return Payload::fail('Conversation not found', [], 'E_NOT_FOUND', 404); } return Payload::ok($data); } catch (\Throwable $e) { Logger::error('Failed to load interaction details', ['error' => $e->getMessage()]); return Payload::fail('Failed to load interaction details', [], 'E_GENERIC', 500); } } }