<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Partner;
use App\Models\ServiceRequest;
use App\Models\User;

class DashboardController extends Controller
{
    public function index()
    {
        $stats = [
            'total_partners' => Partner::count(),
            'total_couriers' => User::where('role', User::ROLE_COURIER)->count(),
            'en_attente' => ServiceRequest::where('status', ServiceRequest::STATUS_EN_ATTENTE)->count(),
            'collecte' => ServiceRequest::whereIn('status', [ServiceRequest::STATUS_COLLECTE, ServiceRequest::STATUS_LIVRE])->count(),
            'ecarts' => ServiceRequest::where('status', ServiceRequest::STATUS_ECART)->count(),
            'non_disponible' => ServiceRequest::where('status', ServiceRequest::STATUS_NON_DISPONIBLE)->count(),
        ];

        $recentRequests = ServiceRequest::with(['partner', 'courier'])
            ->latest()
            ->limit(15)
            ->get();

        return view('admin.dashboard', compact('stats', 'recentRequests'));
    }
}
