using Microsoft.EntityFrameworkCore;
using WarehouseAppSHIPS.Hubs;

var builder = WebApplication.CreateBuilder(args);

// Pipa Database
builder.Services.AddDbContext<WarehouseAppSHIPS.Data.ApplicationDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

// === SISTEM KEAMANAN LOKAL (KEMBALI KE ASAL YANG AMAN) ===
builder.Services.AddAuthentication("Cookies")
    .AddCookie("Cookies", options =>
    {
        options.LoginPath = "/Account/Login"; // Jika belum login, lempar ke halaman ini
    });

builder.Services.AddControllersWithViews();

// === TAMBAHAN UNTUK NOTIFIKASI REAL-TIME ===
builder.Services.AddSignalR();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseRouting();

// Aktifkan Penjaga Gerbang
app.UseAuthentication();
app.UseAuthorization();

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

// === TAMBAHAN UNTUK NOTIFIKASI REAL-TIME ===
app.MapHub<NotificationHub>("/notificationHub");

app.Run();