using Brizco.Identity.Api.Services;

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.UseSerilog();
LoggerConfig.ConfigureSerilog();


var configuration = builder.Configuration;
var siteSetting = configuration.GetSection(nameof(SiteSettings)).Get<SiteSettings>();
builder.Services.Configure<SiteSettings>(configuration.GetSection(nameof(SiteSettings)));

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddCustomDbContext(configuration);
builder.Services.AddCustomController();
builder.Services.AddCustomSwagger(siteSetting.BaseUrl);
builder.Services.AddCustomCores();
builder.Services.AddCustomIdentity();
builder.Services.AddCustomApiVersioning();
builder.Services.AddDataProtection();


builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
{

    var assemblyD = typeof(Program).Assembly;
    builder.RegisterAssemblyTypes(assemblyD)
        .AssignableTo<IScopedDependency>()
        .AsImplementedInterfaces()
        .InstancePerLifetimeScope();

});
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseCustomSwagger(siteSetting.BaseUrl, builder.Environment);
}

app.UseAuthorization();
app.UseAuthentication();
app.UseExceptionHandlerMiddleware();
app.MapControllers();
app.UseCors("CorsPolicy");

DbInitializerService.InitilizeDB(app);



app.Run();
