using API_Access_Control.Endpoints;
using API_Access_Control.Handlers;
using API_Access_Control.Middlewares;
using API_Access_Control.Models.Entities;
using API_Access_Control.Services;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<CloudJwtContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("CLOUD_JWT_Connection"))
);
builder.Services.AddTransient<ConsommateurService>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    Console.WriteLine(">>> Environment = Development!");
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

// Configuring Middlewares
app.UseMiddleware<LoggingMiddleware>();

Endpoints.MapEndpoints(app);

app.Run();