# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.

module Azure::CostManagement::Mgmt::V2019_01_01
  #
  # Exports
  #
  class Exports
    include MsRestAzure

    #
    # Creates and initializes a new instance of the Exports class.
    # @param client service class for accessing basic functionality.
    #
    def initialize(client)
      @client = client
    end

    # @return [CostManagementClient] reference to the CostManagementClient
    attr_reader :client

    #
    # Lists all exports at the given scope.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ExportListResult] operation results.
    #
    def list(scope, custom_headers:nil)
      response = list_async(scope, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Lists all exports at the given scope.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_with_http_info(scope, custom_headers:nil)
      list_async(scope, custom_headers:custom_headers).value!
    end

    #
    # Lists all exports at the given scope.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_async(scope, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{scope}/providers/Microsoft.CostManagement/exports'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CostManagement::Mgmt::V2019_01_01::Models::ExportListResult.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Gets the export for the defined scope by export name.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Export] operation results.
    #
    def get(scope, export_name, custom_headers:nil)
      response = get_async(scope, export_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the export for the defined scope by export name.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def get_with_http_info(scope, export_name, custom_headers:nil)
      get_async(scope, export_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the export for the defined scope by export name.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def get_async(scope, export_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
      fail ArgumentError, 'export_name is nil' if export_name.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{scope}/providers/Microsoft.CostManagement/exports/{exportName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'exportName' => export_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CostManagement::Mgmt::V2019_01_01::Models::Export.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # The operation to create or update a export. Update operation requires latest
    # eTag to be set in the request. You may obtain the latest eTag by performing a
    # get operation. Create operation does not require eTag.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param parameters [Export] Parameters supplied to the CreateOrUpdate Export
    # operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Export] operation results.
    #
    def create_or_update(scope, export_name, parameters, custom_headers:nil)
      response = create_or_update_async(scope, export_name, parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # The operation to create or update a export. Update operation requires latest
    # eTag to be set in the request. You may obtain the latest eTag by performing a
    # get operation. Create operation does not require eTag.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param parameters [Export] Parameters supplied to the CreateOrUpdate Export
    # operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def create_or_update_with_http_info(scope, export_name, parameters, custom_headers:nil)
      create_or_update_async(scope, export_name, parameters, custom_headers:custom_headers).value!
    end

    #
    # The operation to create or update a export. Update operation requires latest
    # eTag to be set in the request. You may obtain the latest eTag by performing a
    # get operation. Create operation does not require eTag.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param parameters [Export] Parameters supplied to the CreateOrUpdate Export
    # operation.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def create_or_update_async(scope, export_name, parameters, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
      fail ArgumentError, 'export_name is nil' if export_name.nil?
      fail ArgumentError, 'parameters is nil' if parameters.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::CostManagement::Mgmt::V2019_01_01::Models::Export.mapper()
      request_content = @client.serialize(request_mapper,  parameters)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = '{scope}/providers/Microsoft.CostManagement/exports/{exportName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'exportName' => export_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:put, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200 || status_code == 201
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CostManagement::Mgmt::V2019_01_01::Models::Export.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end
        # Deserialize Response
        if status_code == 201
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CostManagement::Mgmt::V2019_01_01::Models::Export.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # The operation to delete a export.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def delete(scope, export_name, custom_headers:nil)
      response = delete_async(scope, export_name, custom_headers:custom_headers).value!
      nil
    end

    #
    # The operation to delete a export.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def delete_with_http_info(scope, export_name, custom_headers:nil)
      delete_async(scope, export_name, custom_headers:custom_headers).value!
    end

    #
    # The operation to delete a export.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def delete_async(scope, export_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
      fail ArgumentError, 'export_name is nil' if export_name.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{scope}/providers/Microsoft.CostManagement/exports/{exportName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'exportName' => export_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:delete, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # The operation to execute a export.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def execute(scope, export_name, custom_headers:nil)
      response = execute_async(scope, export_name, custom_headers:custom_headers).value!
      nil
    end

    #
    # The operation to execute a export.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def execute_with_http_info(scope, export_name, custom_headers:nil)
      execute_async(scope, export_name, custom_headers:custom_headers).value!
    end

    #
    # The operation to execute a export.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def execute_async(scope, export_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
      fail ArgumentError, 'export_name is nil' if export_name.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{scope}/providers/Microsoft.CostManagement/exports/{exportName}/run'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'exportName' => export_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # Gets the execution history of a export for the defined scope by export name.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ExportExecutionListResult] operation results.
    #
    def get_execution_history(scope, export_name, custom_headers:nil)
      response = get_execution_history_async(scope, export_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the execution history of a export for the defined scope by export name.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def get_execution_history_with_http_info(scope, export_name, custom_headers:nil)
      get_execution_history_async(scope, export_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the execution history of a export for the defined scope by export name.
    #
    # @param scope [String] The scope associated with export operations. This
    # includes '/subscriptions/{subscriptionId}' for subscription scope,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for
    # resourceGroup scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    # Account scope and
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}'
    # for Department scope,
    # '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
    # for EnrollmentAccount scope.
    # @param export_name [String] Export Name.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def get_execution_history_async(scope, export_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
      fail ArgumentError, 'export_name is nil' if export_name.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{scope}/providers/Microsoft.CostManagement/exports/{exportName}/runHistory'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'exportName' => export_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CostManagement::Mgmt::V2019_01_01::Models::ExportExecutionListResult.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

  end
end
