using Elastic.CommonSchema.Serilog;
using PARR.GeneratorTemplates;
using PARR.GeneratorTemplatesWorker;
using Serilog;
using PARR.TemplateDistributor;

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.InstallGeneratorTemplateServices(builder.Configuration);
builder.Configuration.AddGeneratorTemplateConfigurations(builder.Services);
builder.Services.AddGeneratorTemplateSettings(builder.Configuration);
builder.Services.InstallTemplateDistributorSerivces(builder.Configuration);

builder.Services.AddHostedService<Worker>();

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