using Microsoft.AspNetCore.Cors;
using ms_namingservice.Objects;
using webApiGateway;
using webApiGateway.Objects.Objects;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

//Adding GUI address to CORS policy allow list in order not to block this communication
var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

string guiUrl = configuration.GetValue<string>("EndpointUrls:GUI");

builder.Services.AddCors(options =>
{
    options.AddPolicy("GUI",
        builder =>
        {
            builder.WithOrigins(guiUrl)
                .AllowAnyHeader()
                .AllowAnyMethod();
        });
});


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.UseCors("GUI"); //Manually added due to CORS policy between GUI and WAG

app.Run();

//Automatically generated Program.cs
