using Elastic.CommonSchema.Serilog;
using PARR.Core;
using PARR.Core.Services.Snapshots.Interfaces;
using PARR.DAL;
using PARR.Infrastructure;
using PARR.SnapshotWorker;
using PARR.SnapshotWorker.Settings;
using Serilog;

var builder = Host.CreateApplicationBuilder(args);

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

var commonSettings = new CommonSettings();
builder.Configuration.GetSection(nameof(CommonSettings)).Bind(commonSettings);
builder.Services.AddSingleton(commonSettings);
builder.Services.AddSingleton<ISnapshotSettings>(commonSettings);

builder.Services.AddDalServices(builder.Configuration);
builder.Services.AddCoreServices(builder.Configuration);
builder.Services.AddInfrastructureServices(builder.Configuration);

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

builder.Services.AddHostedService<Worker>();

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