<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class EnsureUserIsDeliveryAgent
{
    public function handle(Request $request, Closure $next): Response
    {
        $user = Auth::guard('sanctum')->user();
        
        if (! $user || ! $user->isDeliveryAgent()) {
            return response()->json([
                'message' => 'Unauthorized. Delivery agent access required.',
            ], 403);
        }

        return $next($request);
    }
}
