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

namespace Aurora.Tenant.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.Tenant.Service"));


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

            services.AddTransient<ITenantService, TenantService>();

            return services;
        }

    }
}
