using Elastic.CommonSchema.Serilog;
using PARR.Core;
using PARR.DAL;
using PARR.EsppApi;
using PARR.Infrastructure;
using PARR.Test;
using PARR.Test.NextRun;
using Serilog;

/*IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((hostContext, services) =>
    {
        //services.InstallEsppApiServices(hostContext.Configuration);
        //services.InstallBllServices(hostContext.Configuration);
        services.InstallDalServices(hostContext.Configuration);
        //services.InstallTemplateDistributorSerivces(hostContext.Configuration);

        services.AddHostedService<Worker>();
    })
    .UseSerilog((hostContext, services, config) =>
        {
            config
                .WriteTo.Console()
                .ReadFrom.Configuration(hostContext.Configuration);
        })
    .Build();*/
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.AddDalServices(builder.Configuration);
builder.Services.AddCoreServices(builder.Configuration);
builder.Services.AddInfrastructureServices(builder.Configuration);
builder.Services.InstallEsppApiServices(builder.Configuration);

builder.Configuration.AddDalConfigurations(builder.Services);
builder.Services.AddDallSettings(builder.Configuration);

builder.Services.AddTransient<NextRunTest>();

builder.Services.AddHostedService<Worker>();

var host = builder.Build();

host.Run();
