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

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

if ($user['role'] !== 'rider') {
    jsonResponse(['success' => false, 'message' => 'Unauthorized'], 403);
}

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    try {
        $available_deliveries = $delivery->getAvailableDeliveries();
        $my_deliveries = $delivery->getRiderDeliveries($user['id']);

        jsonResponse(['success' => true, 'available_deliveries' => $available_deliveries, 'my_deliveries' => $my_deliveries]);
    } catch (Exception $e) {
        jsonResponse(['success' => false, 'message' => $e->getMessage()], 500);
    }
}
?>