using Hcs.Broker.Api.Request.Exception;
using Hcs.Broker.Api.Request.OrgRegistryCommon;
using Hcs.Service.Async.OrgRegistryCommon;

namespace Hcs.Broker.Api
{
    /// <inheritdoc cref="IOrgRegistryCommonApi"/>
    public class OrgRegistryCommonApi(Client client) : ApiBase(client), IOrgRegistryCommonApi
    {
        /// <inheritdoc cref="IOrgRegistryCommonApi"/>
        public async Task<IEnumerable<exportDataProviderResultType>> ExportDataProviderAsync(bool isActual, CancellationToken token = default)
        {
            try
            {
                var request = new ExportDataProviderRequest(client);
                return await request.ExecuteAsync(isActual, token);
            }
            catch (NoResultsRemoteException)
            {
                return [];
            }
        }

        /// <inheritdoc cref="IOrgRegistryCommonApi"/>
        public async Task<IEnumerable<exportOrgRegistryResultType>> ExportOrgRegistryAsync(string ogrn, string kpp, CancellationToken token = default)
        {
            try
            {
                var request = new ExportOrgRegistryRequest(client);
                return await request.ExecuteAsync(ogrn, kpp, token);
            }
            catch (NoResultsRemoteException)
            {
                return [];
            }
        }
    }
}
