<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureSchoolScope
{
    public function handle(Request $request, Closure $next): Response
    {
        if ($request->user()?->role_key === 'super_admin') {
            return $next($request);
        }

        if (! $request->user()?->school_id) {
            abort(403, 'مدرسه کاربر مشخص نیست.');
        }

        return $next($request);
    }
}
