<?php
require_once '../config.php';
require_once '../../includes/Auth.php';
require_once '../../includes/Order.php';

$auth = new Auth();
$user = $auth->requireAuth();

$order = new Order();

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $order_id = $_GET['id'] ?? null;

    if (!$order_id) {
        jsonResponse(['success' => false, 'message' => 'Order ID is required'], 400);
    }

    try {
        // The getOrderDetails method should verify the user ID
        $details = $order->getOrderDetails($order_id, $user['id']);
        jsonResponse(['success' => true, 'data' => $details]);
    } catch (Exception $e) {
        jsonResponse(['success' => false, 'message' => $e->getMessage()], 500);
    }
}
?>