using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    static class Program
    {
        public static ApplicationSetting setting;

        public static IServiceProvider ServiceProvider { get; private set; }

        public static IConfiguration Configuration { get; private set; }


        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            


            Configure();
        }

        private static void Configure()
        {
            var builder = new ConfigurationBuilder()
             .SetBasePath(Directory.GetCurrentDirectory())
             .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            Configuration = builder.Build();    

            setting = Configuration.GetSection("ApplicationSettings").Get<ApplicationSetting>();

            var serviceCollection = new ServiceCollection();
            ConfigureServices(serviceCollection);

            ServiceProvider = serviceCollection.BuildServiceProvider();

            var Form1 = ServiceProvider.GetRequiredService<Form1>();
            Application.Run(Form1);


        }

        private static void ConfigureServices(IServiceCollection services)
        {

            services.AddScoped<IemployeeService, EsbEmployee>();
            services.AddTransient(typeof(Form1));
            services.AddTransient(typeof(EmployeeForm));
            services.AddTransient(typeof(EmployeeViewForm));

            services.AddDbContext<ZkContext>(options => {
                options.UseNpgsql(setting.ConnectionString);
            });
 
        }





    }
}
