false, 'error' => 'Method not allowed']); exit; } $ticketId = isset($_GET['ticket_id']) ? (int)$_GET['ticket_id'] : 0; $offset = isset($_GET['offset']) ? max(0, (int)$_GET['offset']) : 0; $limit = isset($_GET['limit']) ? min(100, max(1, (int)$_GET['limit'])) : 50; if ($ticketId <= 0) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid ticket_id']); exit; } $ticketModel = new TicketModel($conn); $ticket = $ticketModel->getTicketById($ticketId); if (!$ticket || !$ticketModel->canUserAccessTicket($ticket, $currentUser)) { http_response_code(404); echo json_encode(['success' => false, 'error' => 'Ticket not found']); exit; } $commentModel = new CommentModel($conn); $total = $commentModel->getCommentCount($ticketId); $comments = $commentModel->getCommentsByTicketId($ticketId, true, $limit, $offset); echo json_encode([ 'success' => true, 'comments' => $comments, 'total' => $total, 'offset' => $offset, 'limit' => $limit, 'has_more' => ($offset + $limit) < $total, ]);