using FastEndpoints;

namespace SpaceGame.Api.Ships.Api;

public sealed class RemoveShipOrderRequest
{
    public string ShipId { get; set; } = string.Empty;
    public string OrderId { get; set; } = string.Empty;
}

public sealed class RemoveShipOrderHandler(WorldService worldService) : Endpoint<RemoveShipOrderRequest, ShipSnapshot>
{
    public override void Configure()
    {
        Delete("/api/ships/{shipId}/orders/{orderId}");
    }

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

        await SendOkAsync(snapshot, cancellationToken);
    }
}
