using System;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Aurora.Core.EntityFramework;
using Microsoft.EntityFrameworkCore;
using Aurora.Core.Service;
using Aurora.Core.IService;

namespace Aurora.Core.Api
{
    public static class ModuleCoreApi
    {
        public static IServiceCollection AddModuleCoreApi(this IServiceCollection services, IConfiguration configuration)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            services.AddAutoMapper(Assembly.Load("Aurora.Core.Service"));


            services.AddDbContext<ApplicationDbContext>(option =>
                    option.UseMySQL(configuration["ConnectionStrings:MySql"]));
                    
            services.AddDbContext<ApplicationReadonlyDbContext>(option =>
                    option.UseMySQL(configuration["ReadonlyConnectionStrings:MySql"]));

            services.AddTransient<ICategoryService, CategoryService>();
            services.AddTransient<IRocketService, RocketService>();

            return services;
        }

    }
}
