using Knots;
using FastEndpoints;
using FastEndpoints.Swagger;
using Microsoft.OpenApi;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

// On ajoute ici la configuration de la base de données
builder.Services.AddDbContext<KnotsDbContext>();

//On ajoute le CORS au code
builder.Services.AddCors(options =>
{ options.AddDefaultPolicy(policyBuilder =>
    {
        policyBuilder
            .WithOrigins("http://localhost:5250/")
            .WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")
            .AllowAnyHeader();
    });
});

builder.Services.AddFastEndpoints();
builder.Services.SwaggerDocument();

builder.Services.AddAuthentication();
builder.Services.AddAuthorization();

builder.Services.AddAutoMapper(cfg => { }, typeof(Program).Assembly);

// On construit l'application en lui donnant vie
WebApplication app = builder.Build();

app.UseCors();

app.UseSwaggerGen();

app.UseAuthentication()
    .UseAuthorization()
    .UseFastEndpoints(options => 
        { 
            options.Endpoints.RoutePrefix = "API";
            options.Endpoints.ShortNames = true;
        }
    ).UseSwaggerGen();

app.UseHttpsRedirection();

app.Run();