<?php

namespace App\Http\Middleware;

use App\Support\CurrentBusiness;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class SetCurrentBusiness
{
    public function handle(Request $request, Closure $next): Response
    {
        $user = $request->user();

        abort_if($user && $user->is_active === false, 403, 'Your account has been disabled.');

        if ($user?->business) {
            app(CurrentBusiness::class)->set($user->business);
        }

        return $next($request);
    }
}
