using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Strata.Code.DataAccess.Repositories.Interfaces;
using Strata.Code.DataAccess.Repositories;
using System.Reflection;
using Strata.Code.Business.Services;
using Strata.Code.Business.Services.Interfaces;
using Strata.Code.DataAccess.Data;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo
    {
        Title = "Budget Config API",
        Version = "v1",
        Description = "API for managing budget configuration default settings"
    });

    // Include XML comments in Swagger documentation
    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
    c.IncludeXmlComments(xmlPath);
});

// Add your DbContext configuration here
builder.Services.AddDbContext<OnePlanDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddScoped<IBudgetConfigDefaultSettingRepository, BudgetConfigDefaultSettingRepository>();
builder.Services.AddScoped<IBudgetConfigDefaultSettingService, BudgetConfigDefaultSettingService>();

var app = builder.Build();

if (app.Environment.IsDevelopment() || app.Environment.IsStaging())
{
    app.UseSwagger();
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "Budget Config API V1");
    });
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();
