using Hcs.Client.Internal;
using Hcs.Service.Async.HouseManagement;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Hcs.Client.Api.Request.HouseManagement
{
    internal class ExportAccountRequest(ClientBase client) : HouseManagementRequestBase(client)
    {
        protected override bool EnableMinimalResponseWaitDelay => false;

        internal async Task<IEnumerable<exportAccountResultType>> ExecuteAsync(string fiasHouseGuid, CancellationToken token)
        {
            // http://open-gkh.ru/HouseManagement/exportAccountRequest.html
            var request = new exportAccountRequest
            {
                Id = Constants.SIGNED_XML_ELEMENT_ID,
                version = "10.0.1.1",
                Items = [fiasHouseGuid],
                ItemsElementName = [ItemsChoiceType26.FIASHouseGuid]
            };

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

            return result.Items.OfType<exportAccountResultType>();
        }
    }
}
