using Elastic.CommonSchema.Serilog;
using Serilog;
using PARR.EsppOrderLoaderWorker;
using PARR.EsppOrderLoader;

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());
});

builder.Services.InstallEsppOrderLoaderServices(builder.Configuration);
builder.Configuration.AddEsppOrderLoaderConfigurations(builder.Services);
builder.Services.AddEsppOrderLoaderSettings(builder.Configuration);

builder.Services.AddHostedService<Worker>();

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