using Elastic.CommonSchema.Serilog;
using PARR.EsppTemplateSync;
using PARR.EsppTemplateSyncWorker;
using Serilog;

var builder = Host.CreateApplicationBuilder();

builder.Services.AddLogging(config =>
{
    config.ClearProviders();

    var logger = new LoggerConfiguration();

    if (builder.Environment.IsProduction())
        logger.WriteTo.Console(new EcsTextFormatter());
    else
        logger.WriteTo.Console();

    logger.ReadFrom.Configuration(builder.Configuration);

    config.AddSerilog(logger.CreateLogger());
});
//IHost host = Host.CreateDefaultBuilder(args)
//    .ConfigureServices((hostContext, services) =>
//    {
//        services.InstallEsppTemplateSyncServices(hostContext.Configuration);

//        services.AddHostedService<Worker>();
//    })
//    .UseSerilog((hostContext, services, config) =>
//    {
//        if (hostContext.HostingEnvironment.IsProduction())
//            config.WriteTo.Console(new EcsTextFormatter());
//        else
//            config.WriteTo.Console();

//        config.ReadFrom.Configuration(hostContext.Configuration);
//    })
//    .Build();
builder.Services.InstallEsppTemplateSyncServices(builder.Configuration);
builder.Configuration.AddEsppTemplateConfigurations(builder.Services);
builder.Services.AddEsppTemplateSettings(builder.Configuration);

builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
