# 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::Support::Mgmt::V2020_04_01
  #
  # Microsoft Azure Support Resource Provider.
  #
  class Communications
    include MsRestAzure

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

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

    #
    # Check the availability of a resource name. This API should be used to check
    # the uniqueness of the name for adding a new communication to the support
    # ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param check_name_availability_input [CheckNameAvailabilityInput] Input to
    # check.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [CheckNameAvailabilityOutput] operation results.
    #
    def check_name_availability(support_ticket_name, check_name_availability_input, custom_headers:nil)
      response = check_name_availability_async(support_ticket_name, check_name_availability_input, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Check the availability of a resource name. This API should be used to check
    # the uniqueness of the name for adding a new communication to the support
    # ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param check_name_availability_input [CheckNameAvailabilityInput] Input to
    # check.
    # @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 check_name_availability_with_http_info(support_ticket_name, check_name_availability_input, custom_headers:nil)
      check_name_availability_async(support_ticket_name, check_name_availability_input, custom_headers:custom_headers).value!
    end

    #
    # Check the availability of a resource name. This API should be used to check
    # the uniqueness of the name for adding a new communication to the support
    # ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param check_name_availability_input [CheckNameAvailabilityInput] Input to
    # check.
    # @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 check_name_availability_async(support_ticket_name, check_name_availability_input, custom_headers:nil)
      fail ArgumentError, 'support_ticket_name is nil' if support_ticket_name.nil?
      fail ArgumentError, 'check_name_availability_input is nil' if check_name_availability_input.nil?
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.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?

      # Serialize Request
      request_mapper = Azure::Support::Mgmt::V2020_04_01::Models::CheckNameAvailabilityInput.mapper()
      request_content = @client.serialize(request_mapper,  check_name_availability_input)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}/checkNameAvailability'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'supportTicketName' => support_ticket_name,'subscriptionId' => @client.subscription_id},
          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(: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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Support::Mgmt::V2020_04_01::Models::CheckNameAvailabilityOutput.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

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param top [Integer] The number of values to return in the collection.
    # Default is 10 and max is 10.
    # @param filter [String] The filter to apply on the operation. You can filter
    # by communicationType and createdDate properties. CommunicationType supports
    # Equals ('eq') operator and createdDate supports Greater Than ('gt') and
    # Greater Than or Equals ('ge') operators. You may combine the
    # CommunicationType and CreatedDate filters by Logical And ('and') operator.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<CommunicationDetails>] operation results.
    #
    def list(support_ticket_name, top:nil, filter:nil, custom_headers:nil)
      first_page = list_as_lazy(support_ticket_name, top:top, filter:filter, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param top [Integer] The number of values to return in the collection.
    # Default is 10 and max is 10.
    # @param filter [String] The filter to apply on the operation. You can filter
    # by communicationType and createdDate properties. CommunicationType supports
    # Equals ('eq') operator and createdDate supports Greater Than ('gt') and
    # Greater Than or Equals ('ge') operators. You may combine the
    # CommunicationType and CreatedDate filters by Logical And ('and') operator.
    # @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(support_ticket_name, top:nil, filter:nil, custom_headers:nil)
      list_async(support_ticket_name, top:top, filter:filter, custom_headers:custom_headers).value!
    end

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param top [Integer] The number of values to return in the collection.
    # Default is 10 and max is 10.
    # @param filter [String] The filter to apply on the operation. You can filter
    # by communicationType and createdDate properties. CommunicationType supports
    # Equals ('eq') operator and createdDate supports Greater Than ('gt') and
    # Greater Than or Equals ('ge') operators. You may combine the
    # CommunicationType and CreatedDate filters by Logical And ('and') operator.
    # @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(support_ticket_name, top:nil, filter:nil, custom_headers:nil)
      fail ArgumentError, 'support_ticket_name is nil' if support_ticket_name.nil?
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.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 = 'subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'supportTicketName' => support_ticket_name,'subscriptionId' => @client.subscription_id},
          query_params: {'$top' => top,'$filter' => filter,'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::Support::Mgmt::V2020_04_01::Models::CommunicationsListResult.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

    #
    # Returns communication details for a support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication name.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [CommunicationDetails] operation results.
    #
    def get(support_ticket_name, communication_name, custom_headers:nil)
      response = get_async(support_ticket_name, communication_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Returns communication details for a support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication 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(support_ticket_name, communication_name, custom_headers:nil)
      get_async(support_ticket_name, communication_name, custom_headers:custom_headers).value!
    end

    #
    # Returns communication details for a support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication 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(support_ticket_name, communication_name, custom_headers:nil)
      fail ArgumentError, 'support_ticket_name is nil' if support_ticket_name.nil?
      fail ArgumentError, 'communication_name is nil' if communication_name.nil?
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.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 = 'subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications/{communicationName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'supportTicketName' => support_ticket_name,'communicationName' => communication_name,'subscriptionId' => @client.subscription_id},
          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::Support::Mgmt::V2020_04_01::Models::CommunicationDetails.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

    #
    # Adds a new customer communication to an Azure support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication name.
    # @param create_communication_parameters [CommunicationDetails] Communication
    # object.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [CommunicationDetails] operation results.
    #
    def create(support_ticket_name, communication_name, create_communication_parameters, custom_headers:nil)
      response = create_async(support_ticket_name, communication_name, create_communication_parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication name.
    # @param create_communication_parameters [CommunicationDetails] Communication
    # object.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def create_async(support_ticket_name, communication_name, create_communication_parameters, custom_headers:nil)
      # Send request
      promise = begin_create_async(support_ticket_name, communication_name, create_communication_parameters, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
          result_mapper = Azure::Support::Mgmt::V2020_04_01::Models::CommunicationDetails.mapper()
          parsed_response = @client.deserialize(result_mapper, parsed_response)
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Adds a new customer communication to an Azure support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication name.
    # @param create_communication_parameters [CommunicationDetails] Communication
    # object.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [CommunicationDetails] operation results.
    #
    def begin_create(support_ticket_name, communication_name, create_communication_parameters, custom_headers:nil)
      response = begin_create_async(support_ticket_name, communication_name, create_communication_parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Adds a new customer communication to an Azure support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication name.
    # @param create_communication_parameters [CommunicationDetails] Communication
    # object.
    # @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 begin_create_with_http_info(support_ticket_name, communication_name, create_communication_parameters, custom_headers:nil)
      begin_create_async(support_ticket_name, communication_name, create_communication_parameters, custom_headers:custom_headers).value!
    end

    #
    # Adds a new customer communication to an Azure support ticket.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param communication_name [String] Communication name.
    # @param create_communication_parameters [CommunicationDetails] Communication
    # object.
    # @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 begin_create_async(support_ticket_name, communication_name, create_communication_parameters, custom_headers:nil)
      fail ArgumentError, 'support_ticket_name is nil' if support_ticket_name.nil?
      fail ArgumentError, 'communication_name is nil' if communication_name.nil?
      fail ArgumentError, 'create_communication_parameters is nil' if create_communication_parameters.nil?
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.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?

      # Serialize Request
      request_mapper = Azure::Support::Mgmt::V2020_04_01::Models::CommunicationDetails.mapper()
      request_content = @client.serialize(request_mapper,  create_communication_parameters)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications/{communicationName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'supportTicketName' => support_ticket_name,'communicationName' => communication_name,'subscriptionId' => @client.subscription_id},
          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 == 202
          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::Support::Mgmt::V2020_04_01::Models::CommunicationDetails.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

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [CommunicationsListResult] operation results.
    #
    def list_next(next_page_link, custom_headers:nil)
      response = list_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List 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_next_with_http_info(next_page_link, custom_headers:nil)
      list_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List 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_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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::Support::Mgmt::V2020_04_01::Models::CommunicationsListResult.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

    #
    # Lists all communications (attachments not included) for a support ticket.
    # <br/></br> You can also filter support ticket communications by _CreatedDate_
    # or _CommunicationType_ using the $filter parameter. The only type of
    # communication supported today is _Web_. Output will be a paged result with
    # _nextLink_, using which you can retrieve the next set of Communication
    # results. <br/><br/>Support ticket data is available for 12 months after
    # ticket creation. If a ticket was created more than 12 months ago, a request
    # for data might cause an error.
    #
    # @param support_ticket_name [String] Support ticket name.
    # @param top [Integer] The number of values to return in the collection.
    # Default is 10 and max is 10.
    # @param filter [String] The filter to apply on the operation. You can filter
    # by communicationType and createdDate properties. CommunicationType supports
    # Equals ('eq') operator and createdDate supports Greater Than ('gt') and
    # Greater Than or Equals ('ge') operators. You may combine the
    # CommunicationType and CreatedDate filters by Logical And ('and') operator.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [CommunicationsListResult] which provide lazy access to pages of the
    # response.
    #
    def list_as_lazy(support_ticket_name, top:nil, filter:nil, custom_headers:nil)
      response = list_async(support_ticket_name, top:top, filter:filter, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

  end
end
