using log4net.Config;
using MasaBlazorApp3;
using MasaBlazorApp3.DataAccess.Dao;
using MasaBlazorApp3.DataAccess.Impl;
using MasaBlazorApp3.DataAccess;
using MasaBlazorApp3.Finger;
using Microsoft.Extensions.DependencyInjection;
using Photino.Blazor;
using LinqToDB.AspNet;
using LinqToDB;
using Microsoft.Extensions.Configuration;
using LinqToDB.AspNet.Logging;
using Radzen;
using MasaBlazorApp3.Pojo.Config;
using MasaBlazorApp3.Port;

internal class Program
{

    [STAThread]
    private static void Main(string[] args)
    {
        var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args);

        appBuilder.RootComponents.Add<App>("#app");
        appBuilder.Services.AddRadzenComponents();
        // 指纹机工具类
        appBuilder.Services.AddSingleton<FingerprintUtil>();
        // 串口工具类
        appBuilder.Services.AddSingleton<PortUtil>();
        // 登录用户全局存放
        appBuilder.Services.AddSingleton<GlobalStateService>();
        // 框架自带通知服务注入
        appBuilder.Services.AddScoped<NotificationService>(); 
        appBuilder.Services.AddScoped<TooltipService>();
        appBuilder.Services.AddScoped<DialogService>();

        // 注入log
        XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));

        //设置配置文件
        var config = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .Build();
        // 注入配置
        appBuilder.Services.Configure<FingerPojo>(config.GetSection("finger"));
        appBuilder.Services.Configure<SettingConfig>(config.GetSection("setting"));
        appBuilder.Services.Configure<PortConfig>(config.GetSection("port"));
        appBuilder.Services.Configure<DrawerConfig>(config.GetSection("drawer"));
        appBuilder.Services.Configure<fridgeConfig>(config.GetSection("fridge"));
        
        // i18n
        //appBuilder.Services.AddI18nText();
        // 数据库
        appBuilder.Services.AddLinqToDBContext<AppDataConnection>((provider, options) =>
                options.UseMySql(config.GetValue<String>("connectionStrings"))
                .UseDefaultLogging(provider), ServiceLifetime.Transient);
        // dao层数据库操作
        appBuilder.Services.AddScoped<IUserDao, UserDao>();
        appBuilder.Services.AddScoped<IRoleDao, RoleDao>();
        appBuilder.Services.AddScoped<IChannelListDao, ChannelListDao>();
        appBuilder.Services.AddScoped<IOrderInfoDao, OrderInfoDao>();
        appBuilder.Services.AddScoped<IDrugInfoDao, DrugInfoDao>();
        appBuilder.Services.AddScoped<IMachineRecordDao, MachineRecordDao>();
        appBuilder.Services.AddScoped<IInOutInvoiceDao, InOutInvoiceDao>();
        appBuilder.Services.AddScoped<ISettingManuDao, SettingManuDao>();
        appBuilder.Services.AddScoped<IPlanDao, PlanDao>();

        //自选取药
        appBuilder.Services.AddScoped<ISelfTakeDao, SelfTakeDao>();

        //药品批次
        appBuilder.Services.AddScoped<IDrugManuNoDao, DrugManuNoDao>();

        //报表
        appBuilder.Services.AddScoped<IReportDataDao, ReportDataDao>();


        //交接班记录
        appBuilder.Services.AddScoped<IHkcChangeShiftsDao, HkcChangeShiftsDao>();
        //GlobalStateService.connStr = config.GetValue<String>("connectionStrings");
        var app = appBuilder.Build();
        app.MainWindow
            .SetHeight(768)
            .SetWidth(1024)
            .SetIconFile("favicon.ico")
            .SetContextMenuEnabled(false)
#if DEBUG
            .SetFullScreen(false)
#else
            .SetChromeless(true)
            .SetFullScreen(true)
#endif
        ;


        AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
        {
        };
        app.Run();
    }
}