# releans_api
#
# This file was automatically generated by APIMATIC v2.0
# ( https://apimatic.io ).

module ReleansApi
  # MessageController
  class MessageController < BaseController
    @instance = MessageController.new

    class << self
      attr_accessor :instance
    end

    def instance
      self.class.instance
    end

    # List all messages sent by the account.
    # @param [String] accept Required parameter: Example:
    # @return Mixed response from the API call
    def get_all_messages(accept)
      # Prepare query url.
      _path_url = '/message'
      _query_builder = Configuration.get_base_uri
      _query_builder << _path_url
      _query_url = APIHelper.clean_url _query_builder

      # Prepare headers.
      _headers = {
        'Accept' => accept
      }

      # Prepare and execute HttpRequest.
      _request = @http_client.get(
        _query_url,
        headers: _headers
      )
      OAuth2.apply(_request)
      _context = execute_request(_request)
      validate_response(_context)

      # Return appropriate response type.
      decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
        _context.response.raw_body.nil? ||
        _context.response.raw_body.to_s.strip.empty?
      decoded
    end

    # Return the details of the message.
    # @param [String] id Required parameter: Example:
    # @param [String] accept Required parameter: Example:
    # @return Mixed response from the API call
    def get_view_message(id,
                         accept)
      # Prepare query url.
      _path_url = '/message/view'
      _query_builder = Configuration.get_base_uri
      _query_builder << _path_url
      _query_builder = APIHelper.append_url_with_query_parameters(
        _query_builder,
        {
          'id' => id
        },
        array_serialization: Configuration.array_serialization
      )
      _query_url = APIHelper.clean_url _query_builder

      # Prepare headers.
      _headers = {
        'Accept' => accept
      }

      # Prepare and execute HttpRequest.
      _request = @http_client.get(
        _query_url,
        headers: _headers
      )
      OAuth2.apply(_request)
      _context = execute_request(_request)
      validate_response(_context)

      # Return appropriate response type.
      decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
        _context.response.raw_body.nil? ||
        _context.response.raw_body.to_s.strip.empty?
      decoded
    end

    # Send a single message.
    # @param [String] accept Required parameter: Example:
    # @param [String] sender_id Required parameter: Sender id to send the
    # message from.
    # @param [String] mobile_number Required parameter: The mobile number
    # supposed to receive the message.
    # @param [String] message Required parameter: Message text.
    # @return Mixed response from the API call
    def create_send_sms_message(accept,
                                sender_id,
                                mobile_number,
                                message)
      # Prepare query url.
      _path_url = '/message/send'
      _query_builder = Configuration.get_base_uri
      _query_builder << _path_url
      _query_url = APIHelper.clean_url _query_builder

      # Prepare headers.
      _headers = {
        'Accept' => accept
      }

      # Prepare form parameters.
      _parameters = {
        'senderId' => sender_id,
        'mobileNumber' => mobile_number,
        'message' => message
      }
      _parameters = APIHelper.form_encode_parameters(_parameters)

      # Prepare and execute HttpRequest.
      _request = @http_client.post(
        _query_url,
        headers: _headers,
        parameters: _parameters
      )
      OAuth2.apply(_request)
      _context = execute_request(_request)
      validate_response(_context)

      # Return appropriate response type.
      decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
        _context.response.raw_body.nil? ||
        _context.response.raw_body.to_s.strip.empty?
      decoded
    end
  end
end
