using Hcs.Broker.Internal;
using Hcs.Service.Async.NsiCommon;

namespace Hcs.Broker.Api.Request.NsiCommon
{
    internal class ExportNsiListRequest(Client client) : NsiCommonRequestBase(client)
    {
        internal async Task<NsiListType> ExecuteAsync(ListGroup listGroup, CancellationToken token)
        {
            // http://open-gkh.ru/NsiCommon/exportNsiListRequest.html
            var request = new exportNsiListRequest
            {
                Id = Constants.SIGNED_XML_ELEMENT_ID,
                version = "10.0.1.2",
                ListGroup = listGroup
            };

            var result = await SendAndWaitResultAsync(request, async asyncClient =>
            {
                var response = await asyncClient.exportNsiListAsync(CreateRequestHeader(), request);
                return response.AckRequest.Ack;
            }, token);

            return result.Item as NsiListType;
        }
    }
}
