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

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

$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : null;
$user_id = $user['id'];

try {
    $deliveries = $delivery->getUserDeliveries($user_id, $limit);
    
    jsonResponse([
        'success' => true,
        'deliveries' => $deliveries
    ]);
} catch (Exception $e) {
    jsonResponse([
        'success' => false,
        'message' => $e->getMessage()
    ], 500);
}
?>