<?php

declare(strict_types=1);

namespace App\Http\Middleware;

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

class ImpersonationMiddleware
{
    public function handle(Request $request, Closure $next): Response
    {
        if ($request->session()->has('impersonator_id')) {
            $request->merge(['is_impersonating' => true]);
            $request->merge(['impersonator_id' => $request->session()->get('impersonator_id')]);
        }

        return $next($request);
    }
}
