<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use App\Services\LanguageService;

class SetLocale
{
    protected LanguageService $languageService;

    public function __construct(LanguageService $languageService)
    {
        $this->languageService = $languageService;
    }

    public function handle(Request $request, Closure $next)
    {
        $locale = $this->languageService->getLocaleFromRequest();
        $this->languageService->setLocale($locale);

        return $next($request);
    }
}
