<?php
// =====================================================
// POST /ticket_details.php
// Params: id
// Response: single ticket object (not wrapped)
// =====================================================
require_once 'config.php';

$conn = getConnection();

$id = $_POST['id'] ?? '';

if (empty($id)) {
    echo json_encode(["error" => "Ticket ID is required"]);
    exit;
}

$stmt = $conn->prepare("SELECT problem, assign, location, created_at, status, end_time,
                                recharge_id, name, phone, priroty,
                                user_id, check_time, remark, create_by AS created_by
                         FROM ticket WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $ticket = $result->fetch_assoc();
    echo json_encode($ticket);
} else {
    echo json_encode(["error" => "Ticket not found"]);
}

$stmt->close();
$conn->close();
