using Microsoft.EntityFrameworkCore; // Add this for DbContext
using Aberwyn.Data; // Include your data namespace
using MySql.EntityFrameworkCore.Extensions; // For MySQL support

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages(); // Add this line to enable Razor Pages
builder.Services.AddHttpClient(); // Register HttpClient


// Configure your DbContext with MySQL
builder.Services.AddDbContext<BudgetContext>(options =>
    options.UseMySQL(builder.Configuration.GetConnectionString("BudgetDb")));

// Register your BudgetService with a scoped lifetime
builder.Services.AddScoped<BudgetService>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();


// Map default controller route
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

// Map Razor Pages
app.MapRazorPages(); // Add this line to map Razor Pages

app.Run();
