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

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

        internal async Task<IEnumerable<exportHouseResultType>> ExecuteAsync(string fiasHouseGuid, CancellationToken token)
        {
            // http://open-gkh.ru/HouseManagement/exportHouseRequest.html
            var request = new exportHouseRequest
            {
                Id = Constants.SIGNED_XML_ELEMENT_ID,
                version = "15.6.0.1",
                FIASHouseGuid = fiasHouseGuid
            };

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

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