<?php

namespace App\Http\Controllers\Courier;

use App\Http\Controllers\Controller;
use App\Models\ServiceRequest;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index(Request $request)
    {
        $courierId = $request->user()->id;

        $todayRequests = ServiceRequest::with('partner')
            ->where('assigned_courier_id', $courierId)
            ->whereIn('status', [ServiceRequest::STATUS_ASSIGNE])
            ->orderBy('urgency', 'desc')
            ->get();

        $stats = [
            'a_traiter' => $todayRequests->count(),
            'collectees_aujourdhui' => ServiceRequest::where('assigned_courier_id', $courierId)
                ->whereDate('collected_at', today())
                ->count(),
        ];

        return view('courier.dashboard', compact('todayRequests', 'stats'));
    }
}
