using PARR.API.Services.Implementations;
using PARR.API.Services.Interfaces;

namespace PARR.API.Installers
{
    /// <summary>
    /// Самописные сервисы которые используются для АПИ
    /// </summary>
    public static class ApiServicesInstaller
    {
        public static void InstallApiServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton<IUriService>(provider =>
            {
                var accessor = provider.GetRequiredService<IHttpContextAccessor>();
                var request = accessor.HttpContext.Request;
                var absoluteUri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent(), "/");

                return new UriService(absoluteUri);
            });

            services.AddTransient<IClientService, ClientService>();
            services.AddTransient<IAuthService, AuthService>();


        }
    }
}
