using Microsoft.AspNetCore.Authentication.Negotiate;
//using Microsoft.EntityFrameworkCore;
//using TravelExpenses.Data;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSession();

builder.Services.AddControllers()
    .AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.PropertyNamingPolicy = null; // This line is important
    });

// Add Kendo UI services to services container
builder.Services.AddKendo();

// Add db context
//builder.Services.AddDbContext<Entities>(options => options.UseOracle(
//    builder.Configuration.GetConnectionString("TravelExpenses")), ServiceLifetime.Scoped);

// Add services to the container
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
   .AddNegotiate();

builder.Services.AddAuthorization(options =>
{
    // By default, all incoming requests will be authorized according to the default policy.
    options.FallbackPolicy = options.DefaultPolicy;
});
builder.Services.AddRazorPages();

// Add scoped for entities
//builder.Services.AddScoped<Entities>();

var app = builder.Build();

app.UseSession();

app.UseDeveloperExceptionPage();

// Create entities in db
//var entities = app.Services.CreateScope().ServiceProvider.GetService<Entities>();
//entities.Database.EnsureCreated();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

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

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
    // Map the Razor Pages routes
    endpoints.MapRazorPages();

    // Map the default page route
    endpoints.MapFallbackToPage("/Index");
});

app.Run();
