using FastEndpoints;
using Npgsql;

namespace Modules.WMS.Picking.Scan;

public sealed class Endpoint(NpgsqlDataSource dataSource)
    : Endpoint<Request, Response>
{
    public override void Configure()
    {
        Post("/api/wms/picking/tasks/{taskId:guid}/scan");
        Permissions("wms.picking.execute");
    }

    public override async Task HandleAsync(Request req, CancellationToken ct)
    {
        var taskId = Route<Guid>("taskId");
        var handler = new Handler(dataSource);
        var result = await handler.HandleAsync(taskId, req, User.Identity?.Name ?? "unknown", ct);
        await Send.ResponseAsync(result.Body, result.StatusCode, cancellation: ct);
    }
}
