using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using skydiveLogs_api.DomainBusiness;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using skydiveLogs_api.Infrastructure;
using skydiveLogs_api.Infrastructure.Interfaces;
using System.Security.Claims;

namespace skydiveLogs_api.Ioc
{
    public class IocService
    {
        #region Public Constructors

        public IocService(IServiceCollection services,
                          IConfiguration configuration)
        {
            _services = services;
            _configuration = configuration;
        }

        #endregion Public Constructors

        #region Public Methods

        public void Configure()
        {
            _services.AddScoped<IAircraftService, AircraftService>();
            _services.AddScoped<IGearService, GearService>();
            _services.AddScoped<IDropZoneService, DropZoneService>();
            _services.AddScoped<IJumpService, JumpService>();
            _services.AddScoped<IJumpTypeService, JumpTypeService>();
            _services.AddScoped<IStatsService, StatsService>();
            _services.AddScoped<IUserService, UserService>();
            _services.AddScoped<IUserImageService, UserImageService>();
            _services.AddScoped<IInitDbService, InitDbService>();

            _services.AddSingleton<ICacheService, CacheService>();
            _services.AddScoped<IIdentityService, IdentityService>();
            _services.AddScoped<ClaimsPrincipal>(s => s.GetService<IHttpContextAccessor>()?.HttpContext.User);

            _services.AddScoped<IAircraftRepository, AircraftRepository>();
            _services.AddScoped<IDropZoneRepository, DropZoneRepository>();
            _services.AddScoped<IJumpRepository, JumpRepository>();
            _services.AddScoped<IJumpTypeRepository, JumpTypeRepository>();
            _services.AddScoped<IGearRepository, GearRepository>();
            _services.AddScoped<IUserRepository, UserRepository>();
            _services.AddScoped<IUserImageRepository, UserImageRepository>();
            _services.AddScoped<IFavoriteDropZoneRepository, FavoriteDropZoneRepository>();

            string connectionString = _configuration.GetConnectionString("DefaultConnection");
            _services.AddSingleton<IDataProvider>(c => new LiteDbProvider(connectionString));
        }

        #endregion Public Methods

        #region Private Fields

        private readonly IConfiguration _configuration;
        private readonly IServiceCollection _services;

        #endregion Private Fields
    }
}