using Microsoft.AspNetCore.Localization;

namespace QRRapidoApp.Providers
{
    public class CustomRouteDataRequestCultureProvider : IRequestCultureProvider
    {
        public Task<ProviderCultureResult?> DetermineProviderCultureResult(HttpContext httpContext)
        {
            var routeValues = httpContext.GetRouteData()?.Values;
            if (routeValues != null && routeValues.TryGetValue("culture", out var cultureValue))
            {
                var culture = cultureValue?.ToString();
                if (!string.IsNullOrEmpty(culture))
                {
                    // Map the supported cultures
                    var supportedCultures = new[] { "pt-BR", "es-PY" };
                    if (supportedCultures.Contains(culture))
                    {
                        return Task.FromResult<ProviderCultureResult?>(new ProviderCultureResult(culture, culture));
                    }
                }
            }

            return Task.FromResult<ProviderCultureResult?>(null);
        }
    }
}