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

module Azure::Web::Mgmt::V2016_06_01
  #
  # Connections
  #
  class Connections
    include MsRestAzure

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

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

    #
    # Get all connections
    #
    # Gets a list of connections
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param api_version [String] API Version
    # @param top [Integer] The number of items to be included in the result
    # @param filter [String] The filter to apply on the operation
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ApiConnectionDefinitionCollection] operation results.
    #
    def list(subscription_id, resource_group_name, api_version, top:nil, filter:nil, custom_headers:nil)
      response = list_async(subscription_id, resource_group_name, api_version, top:top, filter:filter, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get all connections
    #
    # Gets a list of connections
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param api_version [String] API Version
    # @param top [Integer] The number of items to be included in the result
    # @param filter [String] The filter to apply on the 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 list_with_http_info(subscription_id, resource_group_name, api_version, top:nil, filter:nil, custom_headers:nil)
      list_async(subscription_id, resource_group_name, api_version, top:top, filter:filter, custom_headers:custom_headers).value!
    end

    #
    # Get all connections
    #
    # Gets a list of connections
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param api_version [String] API Version
    # @param top [Integer] The number of items to be included in the result
    # @param filter [String] The filter to apply on the 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 list_async(subscription_id, resource_group_name, api_version, top:nil, filter:nil, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'api_version is nil' if 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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name},
          query_params: {'$top' => top,'$filter' => filter,'api-version' => 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 MsRestAzure::AzureOperationError.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::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinitionCollection.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

    #
    # Get a connection
    #
    # Get a specific connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param api_version [String] API Version
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ApiConnectionDefinition] operation results.
    #
    def get(subscription_id, resource_group_name, connection_name, api_version, custom_headers:nil)
      response = get_async(subscription_id, resource_group_name, connection_name, api_version, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get a connection
    #
    # Get a specific connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param api_version [String] API Version
    # @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(subscription_id, resource_group_name, connection_name, api_version, custom_headers:nil)
      get_async(subscription_id, resource_group_name, connection_name, api_version, custom_headers:custom_headers).value!
    end

    #
    # Get a connection
    #
    # Get a specific connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param api_version [String] API Version
    # @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(subscription_id, resource_group_name, connection_name, api_version, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'connection_name is nil' if connection_name.nil?
      fail ArgumentError, 'api_version is nil' if 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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name,'connectionName' => connection_name},
          query_params: {'api-version' => 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 MsRestAzure::AzureOperationError.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::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinition.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

    #
    # Replace an existing connection
    #
    # Creates or updates a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param connection [ApiConnectionDefinition] The connection
    # @param api_version [String] API Version
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ApiConnectionDefinition] operation results.
    #
    def create_or_update(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:nil)
      response = create_or_update_async(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Replace an existing connection
    #
    # Creates or updates a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param connection [ApiConnectionDefinition] The connection
    # @param api_version [String] API Version
    # @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(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:nil)
      create_or_update_async(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:custom_headers).value!
    end

    #
    # Replace an existing connection
    #
    # Creates or updates a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param connection [ApiConnectionDefinition] The connection
    # @param api_version [String] API Version
    # @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(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'connection_name is nil' if connection_name.nil?
      fail ArgumentError, 'connection is nil' if connection.nil?
      fail ArgumentError, 'api_version is nil' if 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?

      # Serialize Request
      request_mapper = Azure::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinition.mapper()
      request_content = @client.serialize(request_mapper,  connection)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name,'connectionName' => connection_name},
          query_params: {'api-version' => 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 MsRestAzure::AzureOperationError.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::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinition.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::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinition.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

    #
    # Update an existing connection
    #
    # Updates a connection's tags
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param connection [ApiConnectionDefinition] The connection
    # @param api_version [String] API Version
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ApiConnectionDefinition] operation results.
    #
    def update(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:nil)
      response = update_async(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Update an existing connection
    #
    # Updates a connection's tags
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param connection [ApiConnectionDefinition] The connection
    # @param api_version [String] API Version
    # @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 update_with_http_info(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:nil)
      update_async(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:custom_headers).value!
    end

    #
    # Update an existing connection
    #
    # Updates a connection's tags
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param connection [ApiConnectionDefinition] The connection
    # @param api_version [String] API Version
    # @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 update_async(subscription_id, resource_group_name, connection_name, connection, api_version, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'connection_name is nil' if connection_name.nil?
      fail ArgumentError, 'connection is nil' if connection.nil?
      fail ArgumentError, 'api_version is nil' if 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?

      # Serialize Request
      request_mapper = Azure::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinition.mapper()
      request_content = @client.serialize(request_mapper,  connection)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name,'connectionName' => connection_name},
          query_params: {'api-version' => api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:patch, 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 MsRestAzure::AzureOperationError.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::Web::Mgmt::V2016_06_01::Models::ApiConnectionDefinition.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

    #
    # Delete an existing connection
    #
    # Deletes a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param api_version [String] API Version
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def delete(subscription_id, resource_group_name, connection_name, api_version, custom_headers:nil)
      response = delete_async(subscription_id, resource_group_name, connection_name, api_version, custom_headers:custom_headers).value!
      nil
    end

    #
    # Delete an existing connection
    #
    # Deletes a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param api_version [String] API Version
    # @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(subscription_id, resource_group_name, connection_name, api_version, custom_headers:nil)
      delete_async(subscription_id, resource_group_name, connection_name, api_version, custom_headers:custom_headers).value!
    end

    #
    # Delete an existing connection
    #
    # Deletes a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param api_version [String] API Version
    # @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(subscription_id, resource_group_name, connection_name, api_version, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'connection_name is nil' if connection_name.nil?
      fail ArgumentError, 'api_version is nil' if 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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name,'connectionName' => connection_name},
          query_params: {'api-version' => 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 || status_code == 204
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.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

    #
    # Lists consent links for a connection
    #
    # Lists the consent links of a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param list_consent_link [ListConsentLinksDefinition] The consent links
    # @param api_version [String] API Version
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ConsentLinkCollection] operation results.
    #
    def list_consent_links(subscription_id, resource_group_name, connection_name, list_consent_link, api_version, custom_headers:nil)
      response = list_consent_links_async(subscription_id, resource_group_name, connection_name, list_consent_link, api_version, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Lists consent links for a connection
    #
    # Lists the consent links of a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param list_consent_link [ListConsentLinksDefinition] The consent links
    # @param api_version [String] API Version
    # @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_consent_links_with_http_info(subscription_id, resource_group_name, connection_name, list_consent_link, api_version, custom_headers:nil)
      list_consent_links_async(subscription_id, resource_group_name, connection_name, list_consent_link, api_version, custom_headers:custom_headers).value!
    end

    #
    # Lists consent links for a connection
    #
    # Lists the consent links of a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param list_consent_link [ListConsentLinksDefinition] The consent links
    # @param api_version [String] API Version
    # @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_consent_links_async(subscription_id, resource_group_name, connection_name, list_consent_link, api_version, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'connection_name is nil' if connection_name.nil?
      fail ArgumentError, 'list_consent_link is nil' if list_consent_link.nil?
      fail ArgumentError, 'api_version is nil' if 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?

      # Serialize Request
      request_mapper = Azure::Web::Mgmt::V2016_06_01::Models::ListConsentLinksDefinition.mapper()
      request_content = @client.serialize(request_mapper,  list_consent_link)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}/listConsentLinks'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name,'connectionName' => connection_name},
          query_params: {'api-version' => api_version},
          body: request_content,
          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 MsRestAzure::AzureOperationError.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::Web::Mgmt::V2016_06_01::Models::ConsentLinkCollection.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

    #
    # Confirms the consent code for a connection
    #
    # Confirms consent code of a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param confirm_consent_code [ConfirmConsentCodeDefinition] The consent code
    # confirmation
    # @param api_version [String] API Version
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ConfirmConsentCodeDefinition] operation results.
    #
    def confirm_consent_code(subscription_id, resource_group_name, connection_name, confirm_consent_code, api_version, custom_headers:nil)
      response = confirm_consent_code_async(subscription_id, resource_group_name, connection_name, confirm_consent_code, api_version, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Confirms the consent code for a connection
    #
    # Confirms consent code of a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param confirm_consent_code [ConfirmConsentCodeDefinition] The consent code
    # confirmation
    # @param api_version [String] API Version
    # @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 confirm_consent_code_with_http_info(subscription_id, resource_group_name, connection_name, confirm_consent_code, api_version, custom_headers:nil)
      confirm_consent_code_async(subscription_id, resource_group_name, connection_name, confirm_consent_code, api_version, custom_headers:custom_headers).value!
    end

    #
    # Confirms the consent code for a connection
    #
    # Confirms consent code of a connection
    #
    # @param subscription_id [String] Subscription Id
    # @param resource_group_name [String] The resource group
    # @param connection_name [String] Connection name
    # @param confirm_consent_code [ConfirmConsentCodeDefinition] The consent code
    # confirmation
    # @param api_version [String] API Version
    # @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 confirm_consent_code_async(subscription_id, resource_group_name, connection_name, confirm_consent_code, api_version, custom_headers:nil)
      fail ArgumentError, 'subscription_id is nil' if subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'connection_name is nil' if connection_name.nil?
      fail ArgumentError, 'confirm_consent_code is nil' if confirm_consent_code.nil?
      fail ArgumentError, 'api_version is nil' if 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?

      # Serialize Request
      request_mapper = Azure::Web::Mgmt::V2016_06_01::Models::ConfirmConsentCodeDefinition.mapper()
      request_content = @client.serialize(request_mapper,  confirm_consent_code)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}/confirmConsentCode'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => subscription_id,'resourceGroupName' => resource_group_name,'connectionName' => connection_name},
          query_params: {'api-version' => api_version},
          body: request_content,
          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 MsRestAzure::AzureOperationError.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::Web::Mgmt::V2016_06_01::Models::ConfirmConsentCodeDefinition.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
