<?php

namespace App\Http\Controllers\Partner;

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

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

        $recentRequests = ServiceRequest::where('partner_id', $partnerId)
            ->latest()
            ->limit(10)
            ->get();

        $stats = [
            'en_attente' => ServiceRequest::where('partner_id', $partnerId)->where('status', ServiceRequest::STATUS_EN_ATTENTE)->count(),
            'en_cours' => ServiceRequest::where('partner_id', $partnerId)->whereIn('status', [ServiceRequest::STATUS_ASSIGNE, ServiceRequest::STATUS_COLLECTE])->count(),
            'terminees' => ServiceRequest::where('partner_id', $partnerId)->whereIn('status', [ServiceRequest::STATUS_LIVRE, ServiceRequest::STATUS_TRAITE])->count(),
        ];

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