<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\CoachRequest;
use Illuminate\Http\Request;
use Illuminate\View\View;

class CoachRequestIndexController extends Controller
{
    /**
     * فقط نظارت (بند ۵۱: Admin به همه‌ی اطلاعات دسترسی کامل دارد).
     */
    public function index(Request $request): View
    {
        $this->authorize('viewAny', CoachRequest::class);

        $requests = CoachRequest::query()
            ->with(['athlete.user', 'coach.user'])
            ->when($request->filled('status'), fn ($q) => $q->where('status', $request->string('status')))
            ->latest()
            ->paginate(20)
            ->withQueryString();

        return view('admin.coach-requests.index', compact('requests'));
    }
}
