<?php

namespace App\Http\Middleware;

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

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

        if ($user && $user->isCustomer()) {
            return redirect()
                ->route('customer.home')
                ->with('error', 'That area is only available to staff members.');
        }

        return $next($request);
    }
}
