=begin
#Lob

#The Lob API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and uses HTTP response codes to indicate any API errors. <p> Looking for our [previous documentation](https://lob.github.io/legacy-docs/)? 

The version of the OpenAPI document: 1.3.0
Contact: lob-openapi@lob.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 5.2.1

=end

require 'cgi'

module Lob
  class SnapPacksApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # create
    # Creates a new snap_pack given information
    # @param snap_pack_editable [SnapPackEditable] 
    # @param [Hash] opts the optional parameters
    # @option opts [String] :idempotency_key A string of no longer than 256 characters that uniquely identifies this resource. For more help integrating idempotency keys, refer to our [implementation guide](https://www.lob.com/guides#idempotent_request). 
    # @return [SnapPack]
    def create(snap_pack_editable, opts = {})
      data, _status_code, _headers = snap_pack_create_with_http_info(snap_pack_editable, opts)
      data
    end

    # create
    # Creates a new snap_pack given information
    # @param snap_pack_editable [SnapPackEditable] 
    # @param [Hash] opts the optional parameters
    # @option opts [String] :idempotency_key A string of no longer than 256 characters that uniquely identifies this resource. For more help integrating idempotency keys, refer to our [implementation guide](https://www.lob.com/guides#idempotent_request). 
    # @return [Array<(SnapPack, Integer, Hash)>] SnapPack data, response status code and response headers
    def snap_pack_create_with_http_info(snap_pack_editable, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: SnapPacksApi.snap_pack_create ...'
      end
      # verify the required parameter 'snap_pack_editable' is set
      if @api_client.config.client_side_validation && snap_pack_editable.nil?
        fail ArgumentError, "Missing the required parameter 'snap_pack_editable' when calling SnapPacksApi.snap_pack_create"
      end
      if @api_client.config.client_side_validation && !opts[:'idempotency_key'].nil? && opts[:'idempotency_key'].to_s.length > 256
        fail ArgumentError, 'invalid value for "opts[:"idempotency_key"]" when calling SnapPacksApi.snap_pack_create, the character length must be smaller than or equal to 256.'
      end

      # resource path
      local_var_path = '/snap_packs'

      # query parameters
      query_params = opts[:query_params] || {}

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      content_type = @api_client.select_header_content_type(['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data'])
      if !content_type.nil?
          header_params['Content-Type'] = content_type
      end
      header_params[:'Idempotency-Key'] = opts[:'idempotency_key'] if !opts[:'idempotency_key'].nil?

      # form parameters
      form_params = opts[:form_params] || {}

      # http body (model)
      post_body = opts[:debug_body] || @api_client.object_to_http_body(snap_pack_editable)

      # return_type
      return_type = opts[:debug_return_type] || 'SnapPack'

      # auth_names
      auth_names = opts[:debug_auth_names] || ['basicAuth']

      new_options = opts.merge(
        :operation => :"SnapPacksApi.snap_pack_create",
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => return_type
      )

      data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: SnapPacksApi#snap_pack_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # delete
    # Completely removes a snap pack from production. This can only be done if the snap pack's `send_date` has not yet passed.
    # @param snp_id [String] id of the snap_pack
    # @param [Hash] opts the optional parameters
    # @return [SnapPackDeletion]
    def delete(snp_id, opts = {})
      data, _status_code, _headers = snap_pack_delete_with_http_info(snp_id, opts)
      data
    end

    # delete
    # Completely removes a snap pack from production. This can only be done if the snap pack&#39;s &#x60;send_date&#x60; has not yet passed.
    # @param snp_id [String] id of the snap_pack
    # @param [Hash] opts the optional parameters
    # @return [Array<(SnapPackDeletion, Integer, Hash)>] SnapPackDeletion data, response status code and response headers
    def snap_pack_delete_with_http_info(snp_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: SnapPacksApi.snap_pack_delete ...'
      end
      # verify the required parameter 'snp_id' is set
      if @api_client.config.client_side_validation && snp_id.nil?
        fail ArgumentError, "Missing the required parameter 'snp_id' when calling SnapPacksApi.snap_pack_delete"
      end
      pattern = Regexp.new(/^ord_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && snp_id !~ pattern
        fail ArgumentError, "invalid value for 'snp_id' when calling SnapPacksApi.snap_pack_delete, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/snap_packs/{snp_id}'.sub('{' + 'snp_id' + '}', CGI.escape(snp_id.to_s))

      # query parameters
      query_params = opts[:query_params] || {}

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])

      # form parameters
      form_params = opts[:form_params] || {}

      # http body (model)
      post_body = opts[:debug_body]

      # return_type
      return_type = opts[:debug_return_type] || 'SnapPackDeletion'

      # auth_names
      auth_names = opts[:debug_auth_names] || ['basicAuth']

      new_options = opts.merge(
        :operation => :"SnapPacksApi.snap_pack_delete",
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => return_type
      )

      data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: SnapPacksApi#snap_pack_delete\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # get
    # Retrieves the details of an existing snap_pack. You need only supply the unique snap_pack identifier that was returned upon snap_pack creation.
    # @param snp_id [String] id of the snap_pack
    # @param [Hash] opts the optional parameters
    # @return [SnapPack]
    def get(snp_id, opts = {})
      data, _status_code, _headers = snap_pack_retrieve_with_http_info(snp_id, opts)
      data
    end

    # get
    # Retrieves the details of an existing snap_pack. You need only supply the unique snap_pack identifier that was returned upon snap_pack creation.
    # @param snp_id [String] id of the snap_pack
    # @param [Hash] opts the optional parameters
    # @return [Array<(SnapPack, Integer, Hash)>] SnapPack data, response status code and response headers
    def snap_pack_retrieve_with_http_info(snp_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: SnapPacksApi.snap_pack_retrieve ...'
      end
      # verify the required parameter 'snp_id' is set
      if @api_client.config.client_side_validation && snp_id.nil?
        fail ArgumentError, "Missing the required parameter 'snp_id' when calling SnapPacksApi.snap_pack_retrieve"
      end
      pattern = Regexp.new(/^ord_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && snp_id !~ pattern
        fail ArgumentError, "invalid value for 'snp_id' when calling SnapPacksApi.snap_pack_retrieve, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/snap_packs/{snp_id}'.sub('{' + 'snp_id' + '}', CGI.escape(snp_id.to_s))

      # query parameters
      query_params = opts[:query_params] || {}

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])

      # form parameters
      form_params = opts[:form_params] || {}

      # http body (model)
      post_body = opts[:debug_body]

      # return_type
      return_type = opts[:debug_return_type] || 'SnapPack'

      # auth_names
      auth_names = opts[:debug_auth_names] || ['basicAuth']

      new_options = opts.merge(
        :operation => :"SnapPacksApi.snap_pack_retrieve",
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => return_type
      )

      data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: SnapPacksApi#snap_pack_retrieve\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # list
    # Returns a list of your Snap Packs. The snap packs are returned sorted by creation date, with the most recently created snap packs appearing first.
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :limit How many results to return. (default to 10)
    # @option opts [String] :before A reference to a list entry used for paginating to the previous set of entries. This field is pre-populated in the &#x60;previous_url&#x60; field in the return response. 
    # @option opts [String] :after A reference to a list entry used for paginating to the next set of entries. This field is pre-populated in the &#x60;next_url&#x60; field in the return response. 
    # @option opts [Array<String>] :include Request that the response include the total count by specifying &#x60;include[]&#x3D;total_count&#x60;. 
    # @option opts [Hash<String, Time>] :date_created Filter by date created.
    # @option opts [Hash<String, String>] :metadata Filter by metadata key-value pair&#x60;.
    # @option opts [Array<SnapPackSize>] :size The Snap Pack sizes to be returned.
    # @option opts [Boolean] :scheduled * &#x60;true&#x60; - only return orders (past or future) where &#x60;send_date&#x60; is greater than &#x60;date_created&#x60; * &#x60;false&#x60; - only return orders where &#x60;send_date&#x60; is equal to &#x60;date_created&#x60; 
    # @option opts [Hash<String, String>] :send_date Filter by date sent.
    # @option opts [MailType] :mail_type A string designating the mail postage type: * &#x60;usps_first_class&#x60; - (default) * &#x60;usps_standard&#x60; - a [cheaper option](https://lob.com/pricing/print-mail#compare) which is less predictable and takes longer to deliver. &#x60;usps_standard&#x60; cannot be used with &#x60;4x6&#x60; postcards or for any postcards sent outside of the United States.  (default to 'usps_first_class')
    # @option opts [SortBy4] :sort_by Sorts items by ascending or descending dates. Use either &#x60;date_created&#x60; or &#x60;send_date&#x60;, not both. 
    # @return [SnapPackList]
    def list(opts = {})
      data, _status_code, _headers = snap_packs_list_with_http_info(opts)
      data
    end

    # list
    # Returns a list of your Snap Packs. The snap packs are returned sorted by creation date, with the most recently created snap packs appearing first.
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :limit How many results to return. (default to 10)
    # @option opts [String] :before A reference to a list entry used for paginating to the previous set of entries. This field is pre-populated in the &#x60;previous_url&#x60; field in the return response. 
    # @option opts [String] :after A reference to a list entry used for paginating to the next set of entries. This field is pre-populated in the &#x60;next_url&#x60; field in the return response. 
    # @option opts [Array<String>] :include Request that the response include the total count by specifying &#x60;include[]&#x3D;total_count&#x60;. 
    # @option opts [Hash<String, Time>] :date_created Filter by date created.
    # @option opts [Hash<String, String>] :metadata Filter by metadata key-value pair&#x60;.
    # @option opts [Array<SnapPackSize>] :size The Snap Pack sizes to be returned.
    # @option opts [Boolean] :scheduled * &#x60;true&#x60; - only return orders (past or future) where &#x60;send_date&#x60; is greater than &#x60;date_created&#x60; * &#x60;false&#x60; - only return orders where &#x60;send_date&#x60; is equal to &#x60;date_created&#x60; 
    # @option opts [Hash<String, String>] :send_date Filter by date sent.
    # @option opts [MailType] :mail_type A string designating the mail postage type: * &#x60;usps_first_class&#x60; - (default) * &#x60;usps_standard&#x60; - a [cheaper option](https://lob.com/pricing/print-mail#compare) which is less predictable and takes longer to deliver. &#x60;usps_standard&#x60; cannot be used with &#x60;4x6&#x60; postcards or for any postcards sent outside of the United States.  (default to 'usps_first_class')
    # @option opts [SortBy4] :sort_by Sorts items by ascending or descending dates. Use either &#x60;date_created&#x60; or &#x60;send_date&#x60;, not both. 
    # @return [Array<(SnapPackList, Integer, Hash)>] SnapPackList data, response status code and response headers
    def snap_packs_list_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: SnapPacksApi.snap_packs_list ...'
      end
      if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 100
        fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling SnapPacksApi.snap_packs_list, must be smaller than or equal to 100.'
      end

      if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1
        fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling SnapPacksApi.snap_packs_list, must be greater than or equal to 1.'
      end

      if @api_client.config.client_side_validation && !opts[:'metadata'].nil? && opts[:'metadata'].to_s.length > 500
        fail ArgumentError, 'invalid value for "opts[:"metadata"]" when calling SnapPacksApi.snap_packs_list, the character length must be smaller than or equal to 500.'
      end

      pattern = Regexp.new(/[^"\\]{0,500}/)
      if @api_client.config.client_side_validation && !opts[:'metadata'].nil? && opts[:'metadata'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"metadata\"]' when calling SnapPacksApi.snap_packs_list, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/snap_packs'

      # query parameters
      query_params = opts[:query_params] || {}
      query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
      query_params[:'before'] = opts[:'before'] if !opts[:'before'].nil?
      query_params[:'after'] = opts[:'after'] if !opts[:'after'].nil?
      query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :multi) if !opts[:'include'].nil?
      query_params[:'date_created'] = opts[:'date_created'] if !opts[:'date_created'].nil?
      query_params[:'metadata'] = opts[:'metadata'] if !opts[:'metadata'].nil?
      query_params[:'size'] = @api_client.build_collection_param(opts[:'size'], :multi) if !opts[:'size'].nil?
      query_params[:'scheduled'] = opts[:'scheduled'] if !opts[:'scheduled'].nil?
      query_params[:'send_date'] = opts[:'send_date'] if !opts[:'send_date'].nil?
      query_params[:'mail_type'] = opts[:'mail_type'] if !opts[:'mail_type'].nil?
      query_params[:'sort_by'] = opts[:'sort_by'] if !opts[:'sort_by'].nil?

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])

      # form parameters
      form_params = opts[:form_params] || {}

      # http body (model)
      post_body = opts[:debug_body]

      # return_type
      return_type = opts[:debug_return_type] || 'SnapPackList'

      # auth_names
      auth_names = opts[:debug_auth_names] || ['basicAuth']

      new_options = opts.merge(
        :operation => :"SnapPacksApi.snap_packs_list",
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => return_type
      )

      data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: SnapPacksApi#snap_packs_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end
