using Microsoft.EntityFrameworkCore;

using Helpdesk.WebApp.Models;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container
builder.Services.AddTransient<IHelpdeskDbContext, HelpdeskDbContext>();
builder.Services.AddDbContext<HelpdeskDbContext>(options =>
    options.UseSqlite("Data Source=\"" +
        Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) +
        "\\Helpdesk.db\""));

builder.Services.AddControllersWithViews();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

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

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

app.UseRouting();

app.UseAuthorization();

app.UseStatusCodePagesWithRedirects("/Error/");

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

app.Run();
