using Hcs.ClientNet.Internal;
using Hcs.Service.Async.NsiCommon;
using System.Threading;
using System.Threading.Tasks;

namespace Hcs.ClientNet.Api.Request.NsiCommon
{
    internal class ExportNsiItemRequest(ClientBase client) : NsiCommonRequestBase(client)
    {
        internal async Task<NsiItemType> ExecuteAsync(int registryNumber, ListGroup listGroup, CancellationToken token)
        {
            // http://open-gkh.ru/NsiCommon/exportNsiItemRequest.html
            var request = new exportNsiItemRequest
            {
                Id = Constants.SIGNED_XML_ELEMENT_ID,
                version = "10.0.1.2",
                RegistryNumber = registryNumber.ToString(),
                ListGroup = listGroup
            };

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

            return result.Item as NsiItemType;
        }
    }
}
