using Microsoft.AspNetCore.Mvc;
using CarneiroTech.Services;

namespace CarneiroTech.Controllers
{
    public class LanguageController : Controller
    {
        private readonly ILanguageService _languageService;

        public LanguageController(ILanguageService languageService)
        {
            _languageService = languageService;
        }

        [HttpPost]
        public IActionResult SetLanguage(string language, string returnUrl = "/")
        {
            _languageService.SetLanguage(HttpContext, language);

            if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
            {
                return Redirect(returnUrl);
            }

            return RedirectToAction("Index", "Home");
        }
    }
}
