using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetworkResurrector.Api.Domain.Data.DbContexts;
using NetworkResurrector.Api.Domain.Data.Repositories;
using NetworkResurrector.Api.Domain.Repositories;

namespace NetworkResurrector.Api.Domain.Data
{
    public static class DependencyInjectionExtensions
    {
        public static void AddDataAccess(this IServiceCollection services)
        {
            services.AddScoped<INetworkRepository, NetworkRepository>();
            services.AddScoped<ISecurityRepository, SecurityRepository>();

            services
                .AddDbContextPool<NetworkDbContext>(
                 (serviceProvider, options) =>
                 {
                     var configuration = serviceProvider.GetService<IConfiguration>();
                     var connectionString = configuration.GetConnectionString("DatabaseConnection");
                     options.UseSqlServer(connectionString);
                 });
        }
    }
}
