using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.EsppApi.Settings;

namespace PARR.EsppApi
{
    public static class ParrEsppApiInstaller
    {
        public static void InstallEsppApiServices(this IServiceCollection services, IConfiguration configuration)
        {
            // settings
            var esppSettings = new EsppOrderSettings();
            configuration.GetSection(nameof(EsppOrderSettings)).Bind(esppSettings);
            services.AddSingleton(esppSettings);

            EsppUserTimeZoneSettings.TimeZone = esppSettings.EsppUserTimeZone;

            services.AddTransient<IEsppApiService, EsppApiService>();

            services.AddHttpClient<EsppHttpService>(client =>
            {
                client.BaseAddress = new Uri(esppSettings.Url);
                client.DefaultRequestHeaders.Add("EsppUser", esppSettings.UserName);
                client.DefaultRequestHeaders.Add("EsppPassword", esppSettings.Password);
            });

        }
    }
}
