using NeonSprawl.Server.Game.Targeting;

namespace NeonSprawl.Server.Game.Combat;

/// <summary>Dev-only route to reset prototype combat dummy HP for Bruno and manual QA (NEO-83).</summary>
public static class CombatTargetFixtureApi
{
    public static WebApplication MapCombatTargetFixtureApi(this WebApplication app)
    {
        app.MapPost(
            "/game/__dev/combat-targets-fixture",
            (CombatTargetFixtureRequest? body, ICombatEntityHealthStore healthStore) =>
            {
                if (body is null || body.SchemaVersion != CombatTargetFixtureRequest.CurrentSchemaVersion)
                {
                    return Results.BadRequest();
                }

                foreach (var id in PrototypeTargetRegistry.GetPrototypeTargetIdsInOrder())
                {
                    if (!healthStore.TryResetToFull(id, out _))
                    {
                        return Results.NotFound();
                    }
                }

                return Results.Json(
                    new CombatTargetFixtureResponse
                    {
                        Applied = true,
                    });
            });

        return app;
    }
}
