=begin
#BillForward REST API

#No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)

OpenAPI spec version: 1.0.0

Generated by: https://github.com/swagger-api/swagger-codegen.git

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=end

require "uri"

module BillForward
  class CouponinstanceApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end

    # Create a coupon-instance.
    # {\"nickname\":\"Create a new coupon\",\"request\":\"createCouponInstanceRequest.html\",\"response\":\"createCouponInstanceResponse.html\"}
    # @param coupon_instance The coupon-instance object to be created.
    # @param [Hash] opts the optional parameters
    # @return [CouponInstancePagedMetadata]
    def create_coupon_instance(coupon_instance, opts = {})
      data, _status_code, _headers = create_coupon_instance_with_http_info(coupon_instance, opts)
      return data
    end

    # Create a coupon-instance.
    # {\&quot;nickname\&quot;:\&quot;Create a new coupon\&quot;,\&quot;request\&quot;:\&quot;createCouponInstanceRequest.html\&quot;,\&quot;response\&quot;:\&quot;createCouponInstanceResponse.html\&quot;}
    # @param coupon_instance The coupon-instance object to be created.
    # @param [Hash] opts the optional parameters
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def create_coupon_instance_with_http_info(coupon_instance, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.create_coupon_instance ..."
      end
      # verify the required parameter 'coupon_instance' is set
      fail ArgumentError, "Missing the required parameter 'coupon_instance' when calling CouponinstanceApi.create_coupon_instance" if coupon_instance.nil?
      # resource path
      local_var_path = "/coupon-instances".sub('{format}','json')

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['text/xml', 'application/xml', 'application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['application/json']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(coupon_instance)
      auth_names = []
      data, status_code, headers = @api_client.call_api(:POST, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#create_coupon_instance\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Retire a coupon-instance, specified by the coupon-instance-ID parameter.
    # {\"nickname\":\"Delete a coupon\",\"response\":\"deleteCouponInstanceByID.html\"}
    # @param coupon_instance_id ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @return [CouponInstancePagedMetadata]
    def delete_coupon_instance(coupon_instance_id, opts = {})
      data, _status_code, _headers = delete_coupon_instance_with_http_info(coupon_instance_id, opts)
      return data
    end

    # Retire a coupon-instance, specified by the coupon-instance-ID parameter.
    # {\&quot;nickname\&quot;:\&quot;Delete a coupon\&quot;,\&quot;response\&quot;:\&quot;deleteCouponInstanceByID.html\&quot;}
    # @param coupon_instance_id ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def delete_coupon_instance_with_http_info(coupon_instance_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.delete_coupon_instance ..."
      end
      # verify the required parameter 'coupon_instance_id' is set
      fail ArgumentError, "Missing the required parameter 'coupon_instance_id' when calling CouponinstanceApi.delete_coupon_instance" if coupon_instance_id.nil?
      # resource path
      local_var_path = "/coupon-instances/{coupon-instance-ID}".sub('{format}','json').sub('{' + 'coupon-instance-ID' + '}', coupon_instance_id.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['text/plain']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#delete_coupon_instance\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a collection of attachable coupon-instances. An attachable coupon-instance has at least one remaining use, and is not deleted. By default 10 values are returned. Records are returned in natural order.
    # {\"nickname\":\"Get attachable coupons\",\"response\":\"getCouponInstanceAllAttachable.html\"}
    # @param attachableness The attachableness of the coupon-instance.
    # @param has_code Whether the coupon-instances have coupon codes or not.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return. (default to 0)
    # @option opts [Integer] :records The maximum number of coupon-instances to return. (default to 10)
    # @option opts [String] :order_by Specify a field used to order the result set. (default to created)
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC. (default to DESC)
    # @return [CouponInstancePagedMetadata]
    def get_all_attachable_coupon_instances(attachableness, has_code, opts = {})
      data, _status_code, _headers = get_all_attachable_coupon_instances_with_http_info(attachableness, has_code, opts)
      return data
    end

    # Returns a collection of attachable coupon-instances. An attachable coupon-instance has at least one remaining use, and is not deleted. By default 10 values are returned. Records are returned in natural order.
    # {\&quot;nickname\&quot;:\&quot;Get attachable coupons\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceAllAttachable.html\&quot;}
    # @param attachableness The attachableness of the coupon-instance.
    # @param has_code Whether the coupon-instances have coupon codes or not.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return.
    # @option opts [Integer] :records The maximum number of coupon-instances to return.
    # @option opts [String] :order_by Specify a field used to order the result set.
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_all_attachable_coupon_instances_with_http_info(attachableness, has_code, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_all_attachable_coupon_instances ..."
      end
      # verify the required parameter 'attachableness' is set
      fail ArgumentError, "Missing the required parameter 'attachableness' when calling CouponinstanceApi.get_all_attachable_coupon_instances" if attachableness.nil?
      # verify the required parameter 'has_code' is set
      fail ArgumentError, "Missing the required parameter 'has_code' when calling CouponinstanceApi.get_all_attachable_coupon_instances" if has_code.nil?
      if opts[:'order'] && !['ASC', 'DESC'].include?(opts[:'order'])
        fail ArgumentError, 'invalid value for "order", must be one of ASC, DESC'
      end
      # resource path
      local_var_path = "/coupon-instances/attachable/{attachableness}/{has_code}".sub('{format}','json').sub('{' + 'attachableness' + '}', attachableness.to_s).sub('{' + 'has_code' + '}', has_code.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'records'] = opts[:'records'] if !opts[:'records'].nil?
      query_params[:'order_by'] = opts[:'order_by'] if !opts[:'order_by'].nil?
      query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = []
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_all_attachable_coupon_instances\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a collection of coupon-instances. By default 10 values are returned. Records are returned in natural order.
    # {\"nickname\":\"Get all coupons\",\"response\":\"getCouponInstanceAll.html\"}
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return. (default to 0)
    # @option opts [Integer] :records The maximum number of coupon-instances to return. (default to 10)
    # @option opts [String] :order_by Specify a field used to order the result set. (default to created)
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC. (default to DESC)
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned. (default to true)
    # @return [CouponInstancePagedMetadata]
    def get_all_coupon_instances(opts = {})
      data, _status_code, _headers = get_all_coupon_instances_with_http_info(opts)
      return data
    end

    # Returns a collection of coupon-instances. By default 10 values are returned. Records are returned in natural order.
    # {\&quot;nickname\&quot;:\&quot;Get all coupons\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceAll.html\&quot;}
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return.
    # @option opts [Integer] :records The maximum number of coupon-instances to return.
    # @option opts [String] :order_by Specify a field used to order the result set.
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC.
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_all_coupon_instances_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_all_coupon_instances ..."
      end
      if opts[:'order'] && !['ASC', 'DESC'].include?(opts[:'order'])
        fail ArgumentError, 'invalid value for "order", must be one of ASC, DESC'
      end
      # resource path
      local_var_path = "/coupon-instances".sub('{format}','json')

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'records'] = opts[:'records'] if !opts[:'records'].nil?
      query_params[:'order_by'] = opts[:'order_by'] if !opts[:'order_by'].nil?
      query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?
      query_params[:'include_retired'] = opts[:'include_retired'] if !opts[:'include_retired'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = []
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_all_coupon_instances\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a collection of coupon-instances, specified by coupon-code parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\"nickname\":\"Retrieve by coupon code\",\"response\":\"getCouponInstanceByCouponCode.html\"}
    # @param coupon_code The string coupon-code of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return. (default to 0)
    # @option opts [Integer] :records The maximum number of coupon-instances to return. (default to 10)
    # @option opts [String] :order_by Specify a field used to order the result set. (default to created)
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC. (default to DESC)
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned. (default to true)
    # @return [CouponInstancePagedMetadata]
    def get_coupon_instance_by_coupon_code(coupon_code, opts = {})
      data, _status_code, _headers = get_coupon_instance_by_coupon_code_with_http_info(coupon_code, opts)
      return data
    end

    # Returns a collection of coupon-instances, specified by coupon-code parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\&quot;nickname\&quot;:\&quot;Retrieve by coupon code\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceByCouponCode.html\&quot;}
    # @param coupon_code The string coupon-code of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return.
    # @option opts [Integer] :records The maximum number of coupon-instances to return.
    # @option opts [String] :order_by Specify a field used to order the result set.
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC.
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_coupon_instance_by_coupon_code_with_http_info(coupon_code, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_coupon_instance_by_coupon_code ..."
      end
      # verify the required parameter 'coupon_code' is set
      fail ArgumentError, "Missing the required parameter 'coupon_code' when calling CouponinstanceApi.get_coupon_instance_by_coupon_code" if coupon_code.nil?
      if opts[:'order'] && !['ASC', 'DESC'].include?(opts[:'order'])
        fail ArgumentError, 'invalid value for "order", must be one of ASC, DESC'
      end
      # resource path
      local_var_path = "/coupon-instances/coupon/{coupon-code}".sub('{format}','json').sub('{' + 'coupon-code' + '}', coupon_code.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'records'] = opts[:'records'] if !opts[:'records'].nil?
      query_params[:'order_by'] = opts[:'order_by'] if !opts[:'order_by'].nil?
      query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?
      query_params[:'include_retired'] = opts[:'include_retired'] if !opts[:'include_retired'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['text/plain']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_coupon_instance_by_coupon_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a collection of coupon-instances, specified by coupon-definition-ID parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\"nickname\":\"Retrieve by coupon definition\",\"response\":\"getCouponInstanceByCouponDefinitionID.html\"}
    # @param coupon_definition_id The string coupon-definition-ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return. (default to 0)
    # @option opts [Integer] :records The maximum number of coupon-instances to return. (default to 10)
    # @option opts [String] :order_by Specify a field used to order the result set. (default to created)
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC. (default to DESC)
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned. (default to true)
    # @return [CouponInstancePagedMetadata]
    def get_coupon_instance_by_coupon_definition_id(coupon_definition_id, opts = {})
      data, _status_code, _headers = get_coupon_instance_by_coupon_definition_id_with_http_info(coupon_definition_id, opts)
      return data
    end

    # Returns a collection of coupon-instances, specified by coupon-definition-ID parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\&quot;nickname\&quot;:\&quot;Retrieve by coupon definition\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceByCouponDefinitionID.html\&quot;}
    # @param coupon_definition_id The string coupon-definition-ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return.
    # @option opts [Integer] :records The maximum number of coupon-instances to return.
    # @option opts [String] :order_by Specify a field used to order the result set.
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC.
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_coupon_instance_by_coupon_definition_id_with_http_info(coupon_definition_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_coupon_instance_by_coupon_definition_id ..."
      end
      # verify the required parameter 'coupon_definition_id' is set
      fail ArgumentError, "Missing the required parameter 'coupon_definition_id' when calling CouponinstanceApi.get_coupon_instance_by_coupon_definition_id" if coupon_definition_id.nil?
      if opts[:'order'] && !['ASC', 'DESC'].include?(opts[:'order'])
        fail ArgumentError, 'invalid value for "order", must be one of ASC, DESC'
      end
      # resource path
      local_var_path = "/coupon-instances/coupon-definition/{coupon-definition-ID}".sub('{format}','json').sub('{' + 'coupon-definition-ID' + '}', coupon_definition_id.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'records'] = opts[:'records'] if !opts[:'records'].nil?
      query_params[:'order_by'] = opts[:'order_by'] if !opts[:'order_by'].nil?
      query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?
      query_params[:'include_retired'] = opts[:'include_retired'] if !opts[:'include_retired'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['text/plain']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_coupon_instance_by_coupon_definition_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a single coupon-instance, specified by the coupon-instance-ID parameter.
    # {\"nickname\":\"Get existing coupon\",\"response\":\"getCouponInstanceByID.html\"}
    # @param coupon_instance_id ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @return [CouponInstancePagedMetadata]
    def get_coupon_instance_by_id(coupon_instance_id, opts = {})
      data, _status_code, _headers = get_coupon_instance_by_id_with_http_info(coupon_instance_id, opts)
      return data
    end

    # Returns a single coupon-instance, specified by the coupon-instance-ID parameter.
    # {\&quot;nickname\&quot;:\&quot;Get existing coupon\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceByID.html\&quot;}
    # @param coupon_instance_id ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_coupon_instance_by_id_with_http_info(coupon_instance_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_coupon_instance_by_id ..."
      end
      # verify the required parameter 'coupon_instance_id' is set
      fail ArgumentError, "Missing the required parameter 'coupon_instance_id' when calling CouponinstanceApi.get_coupon_instance_by_id" if coupon_instance_id.nil?
      # resource path
      local_var_path = "/coupon-instances/{coupon-instance-ID}".sub('{format}','json').sub('{' + 'coupon-instance-ID' + '}', coupon_instance_id.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['text/plain']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_coupon_instance_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a collection of coupon-instances, specified by target-ID parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\"nickname\":\"Retrieve by target\",\"response\":\"getCouponInstanceByTargetID.html\"}
    # @param target_id The string target-ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return. (default to 0)
    # @option opts [Integer] :records The maximum number of coupon-instances to return. (default to 10)
    # @option opts [String] :order_by Specify a field used to order the result set. (default to created)
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC. (default to DESC)
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned. (default to true)
    # @return [CouponInstancePagedMetadata]
    def get_coupon_instance_by_target_id(target_id, opts = {})
      data, _status_code, _headers = get_coupon_instance_by_target_id_with_http_info(target_id, opts)
      return data
    end

    # Returns a collection of coupon-instances, specified by target-ID parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\&quot;nickname\&quot;:\&quot;Retrieve by target\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceByTargetID.html\&quot;}
    # @param target_id The string target-ID of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return.
    # @option opts [Integer] :records The maximum number of coupon-instances to return.
    # @option opts [String] :order_by Specify a field used to order the result set.
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC.
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_coupon_instance_by_target_id_with_http_info(target_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_coupon_instance_by_target_id ..."
      end
      # verify the required parameter 'target_id' is set
      fail ArgumentError, "Missing the required parameter 'target_id' when calling CouponinstanceApi.get_coupon_instance_by_target_id" if target_id.nil?
      if opts[:'order'] && !['ASC', 'DESC'].include?(opts[:'order'])
        fail ArgumentError, 'invalid value for "order", must be one of ASC, DESC'
      end
      # resource path
      local_var_path = "/coupon-instances/target/{target-ID}".sub('{format}','json').sub('{' + 'target-ID' + '}', target_id.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'records'] = opts[:'records'] if !opts[:'records'].nil?
      query_params[:'order_by'] = opts[:'order_by'] if !opts[:'order_by'].nil?
      query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?
      query_params[:'include_retired'] = opts[:'include_retired'] if !opts[:'include_retired'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['text/plain']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_coupon_instance_by_target_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Returns a collection of coupon-instances, specified by target parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\"nickname\":\"Retrieve by target type\",\"response\":\"getCouponInstanceByTarget.html\"}
    # @param target The string target of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return. (default to 0)
    # @option opts [Integer] :records The maximum number of coupon-instances to return. (default to 10)
    # @option opts [String] :order_by Specify a field used to order the result set. (default to created)
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC. (default to DESC)
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned. (default to true)
    # @return [CouponInstancePagedMetadata]
    def get_coupon_instance_by_target_type(target, opts = {})
      data, _status_code, _headers = get_coupon_instance_by_target_type_with_http_info(target, opts)
      return data
    end

    # Returns a collection of coupon-instances, specified by target parameter. By default 10 coupon-instances are returned. Records are returned in natural order.
    # {\&quot;nickname\&quot;:\&quot;Retrieve by target type\&quot;,\&quot;response\&quot;:\&quot;getCouponInstanceByTarget.html\&quot;}
    # @param target The string target of the coupon-instance.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :organizations A list of organization-IDs used to restrict the scope of API calls.
    # @option opts [Integer] :offset The offset from the first coupon-instance to return.
    # @option opts [Integer] :records The maximum number of coupon-instances to return.
    # @option opts [String] :order_by Specify a field used to order the result set.
    # @option opts [String] :order Ihe direction of any ordering, either ASC or DESC.
    # @option opts [BOOLEAN] :include_retired Whether retired coupon-instances should be returned.
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def get_coupon_instance_by_target_type_with_http_info(target, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.get_coupon_instance_by_target_type ..."
      end
      # verify the required parameter 'target' is set
      fail ArgumentError, "Missing the required parameter 'target' when calling CouponinstanceApi.get_coupon_instance_by_target_type" if target.nil?
      # verify enum value
      unless ['none', 'subscription', 'account'].include?(target)
        fail ArgumentError, "invalid value for 'target', must be one of none, subscription, account"
      end
      if opts[:'order'] && !['ASC', 'DESC'].include?(opts[:'order'])
        fail ArgumentError, 'invalid value for "order", must be one of ASC, DESC'
      end
      # resource path
      local_var_path = "/coupon-instances/target-entity/{target}".sub('{format}','json').sub('{' + 'target' + '}', target.to_s)

      # query parameters
      query_params = {}
      query_params[:'organizations'] = @api_client.build_collection_param(opts[:'organizations'], :multi) if !opts[:'organizations'].nil?
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'records'] = opts[:'records'] if !opts[:'records'].nil?
      query_params[:'order_by'] = opts[:'order_by'] if !opts[:'order_by'].nil?
      query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?
      query_params[:'include_retired'] = opts[:'include_retired'] if !opts[:'include_retired'].nil?

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = []
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = []
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#get_coupon_instance_by_target_type\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Update a coupon-instance.
    # {\"nickname\":\"Update a coupon\",\"request\":\"updateCouponInstanceRequest.html\",\"response\":\"updateCouponInstanceResponse.html\"}
    # @param coupon_instance The coupon-instance object to be updated.
    # @param [Hash] opts the optional parameters
    # @return [CouponInstancePagedMetadata]
    def update_coupon_instance(coupon_instance, opts = {})
      data, _status_code, _headers = update_coupon_instance_with_http_info(coupon_instance, opts)
      return data
    end

    # Update a coupon-instance.
    # {\&quot;nickname\&quot;:\&quot;Update a coupon\&quot;,\&quot;request\&quot;:\&quot;updateCouponInstanceRequest.html\&quot;,\&quot;response\&quot;:\&quot;updateCouponInstanceResponse.html\&quot;}
    # @param coupon_instance The coupon-instance object to be updated.
    # @param [Hash] opts the optional parameters
    # @return [Array<(CouponInstancePagedMetadata, Fixnum, Hash)>] CouponInstancePagedMetadata data, response status code and response headers
    def update_coupon_instance_with_http_info(coupon_instance, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: CouponinstanceApi.update_coupon_instance ..."
      end
      # verify the required parameter 'coupon_instance' is set
      fail ArgumentError, "Missing the required parameter 'coupon_instance' when calling CouponinstanceApi.update_coupon_instance" if coupon_instance.nil?
      # resource path
      local_var_path = "/coupon-instances".sub('{format}','json')

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # HTTP header 'Accept' (if needed)
      local_header_accept = ['text/xml', 'application/xml', 'application/json']
      local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result

      # HTTP header 'Content-Type'
      local_header_content_type = ['application/json']
      header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(coupon_instance)
      auth_names = []
      data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CouponInstancePagedMetadata')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: CouponinstanceApi#update_coupon_instance\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end
