<?php

namespace App\Http\Controllers\PublicSite;

use App\Http\Controllers\Controller;
use App\Models\School;
use Illuminate\Contracts\View\View;

class SchoolController extends Controller
{
    public function index(): View
    {
        return view('public.schools.index', [
            'schools' => School::active()
                ->ordered()
                ->with(['programmes' => fn ($q) => $q->active()->ordered()])
                ->get(),
        ]);
    }

    public function show(School $school): View
    {
        abort_unless($school->status->value === 'active', 404);

        $school->load([
            'departments' => fn ($q) => $q->active(),
            'programmes' => fn ($q) => $q->active()->ordered(),
        ]);

        return view('public.schools.show', compact('school'));
    }
}
