<?php

namespace App\Http\Middleware;

use App\Services\I18n\LocaleResolver;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class SetLocale
{
    public function __construct(private readonly LocaleResolver $resolver) {}

    public function handle(Request $request, Closure $next): Response
    {
        $locale = $this->resolver->forRequest($request);
        app()->setLocale($locale);

        return $next($request);
    }
}
