using FastEndpoints;
using Shared.Excel;

namespace Modules.Common.Imports.Endpoints;

public sealed class GetSessionEndpoint(ImportRepository repository)
    : EndpointWithoutRequest<ImportSessionDto>
{
    public override void Configure()
    {
        Get("/api/imports/sessions/{sessionId:guid}");
        Permissions("imports.execute");
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        var id = Route<Guid>("sessionId");
        var session = await repository.GetAsync(id, ImportIdentity.TenantId(User), ImportIdentity.UserId(User), includeErrors: true, ct);
        if (session is null) { await Send.NotFoundAsync(ct); return; }
        await Send.OkAsync(session, ct);
    }
}
