using FastEndpoints;

namespace SpaceGame.Api.PlayerFaction.Api;

public sealed class UpdatePlayerStrategicIntentHandler(WorldService worldService) : Endpoint<PlayerStrategicIntentCommandRequest, PlayerFactionSnapshot>
{
    public override void Configure()
    {
        Put("/api/player-faction/strategic-intent");
    }

    public override async Task HandleAsync(PlayerStrategicIntentCommandRequest request, CancellationToken cancellationToken)
    {
        var snapshot = worldService.UpdatePlayerStrategicIntent(request);
        if (snapshot is null)
        {
            await SendNotFoundAsync(cancellationToken);
            return;
        }

        await SendOkAsync(snapshot, cancellationToken);
    }
}
