using NeonSprawl.Server.Game.AbilityInput;
using NeonSprawl.Server.Game.Interaction;
using NeonSprawl.Server.Game.Items;
using NeonSprawl.Server.Game.Mastery;
using NeonSprawl.Server.Game.PositionState;
using NeonSprawl.Server.Game.Skills;
using NeonSprawl.Server.Game.Targeting;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPositionStateStore(builder.Configuration);
builder.Services.AddHotbarLoadoutStore(builder.Configuration);
builder.Services.AddSkillProgressionStore(builder.Configuration);
builder.Services.AddPerkStateStore(builder.Configuration);
builder.Services.AddAbilityCooldownStore();
builder.Services.AddSingleton<IPlayerTargetLockStore, InMemoryPlayerTargetLockStore>();
builder.Services.AddSkillDefinitionCatalog(builder.Configuration);
builder.Services.AddItemDefinitionCatalog(builder.Configuration);
builder.Services.AddMasteryCatalog(builder.Configuration);

var app = builder.Build();
_ = app.Services.GetRequiredService<SkillDefinitionCatalog>();
_ = app.Services.GetRequiredService<ItemDefinitionCatalog>();
_ = app.Services.GetRequiredService<MasteryCatalog>();
_ = app.Services.GetRequiredService<ISkillLevelCurve>();

app.MapGet("/", () => Results.Text(
    "Neon Sprawl game server — GET /health for JSON status.",
    "text/plain"));

app.MapGet("/health", () => Results.Json(new
{
    status = "ok",
    service = "NeonSprawl.Server",
}));

app.MapPositionStateApi();
app.MapInteractionApi();
app.MapInteractablesWorldApi();
app.MapSkillDefinitionsWorldApi();
app.MapSkillProgressionSnapshotApi();
app.MapPerkStateApi();
if (app.Environment.IsDevelopment() ||
    app.Environment.IsEnvironment("Testing") ||
    app.Configuration.GetValue<bool>("Game:EnableMasteryFixtureApi"))
{
    app.MapMasteryFixtureApi();
}

app.MapTargetingApi();
app.MapHotbarLoadoutApi();
app.MapCooldownSnapshotApi();
app.MapAbilityCastApi();

app.Run();
