=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 UploadsApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # get_export
    # Retrieves the details of an existing export. You need only supply the unique export identifier that was returned upon export creation. If you try retrieving an export immediately after creating one (i.e., before we're done processing the export), you will get back an export object with `state = in_progress`.
    # @param upl_id [String] ID of the upload
    # @param ex_id [String] ID of the export
    # @param [Hash] opts the optional parameters
    # @return [Export]
    def get_export(upl_id, ex_id, opts = {})
      data, _status_code, _headers = export_retrieve_with_http_info(upl_id, ex_id, opts)
      data
    end

    # get_export
    # Retrieves the details of an existing export. You need only supply the unique export identifier that was returned upon export creation. If you try retrieving an export immediately after creating one (i.e., before we&#39;re done processing the export), you will get back an export object with &#x60;state &#x3D; in_progress&#x60;.
    # @param upl_id [String] ID of the upload
    # @param ex_id [String] ID of the export
    # @param [Hash] opts the optional parameters
    # @return [Array<(Export, Integer, Hash)>] Export data, response status code and response headers
    def export_retrieve_with_http_info(upl_id, ex_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: UploadsApi.export_retrieve ...'
      end
      # verify the required parameter 'upl_id' is set
      if @api_client.config.client_side_validation && upl_id.nil?
        fail ArgumentError, "Missing the required parameter 'upl_id' when calling UploadsApi.export_retrieve"
      end
      pattern = Regexp.new(/^upl_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && upl_id !~ pattern
        fail ArgumentError, "invalid value for 'upl_id' when calling UploadsApi.export_retrieve, must conform to the pattern #{pattern}."
      end

      # verify the required parameter 'ex_id' is set
      if @api_client.config.client_side_validation && ex_id.nil?
        fail ArgumentError, "Missing the required parameter 'ex_id' when calling UploadsApi.export_retrieve"
      end
      pattern = Regexp.new(/^ex_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && ex_id !~ pattern
        fail ArgumentError, "invalid value for 'ex_id' when calling UploadsApi.export_retrieve, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/uploads/{upl_id}/exports/{ex_id}'.sub('{' + 'upl_id' + '}', CGI.escape(upl_id.to_s)).sub('{' + 'ex_id' + '}', CGI.escape(ex_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] || 'Export'

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

      new_options = opts.merge(
        :operation => :"UploadsApi.export_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: UploadsApi#export_retrieve\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

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

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

      # resource path
      local_var_path = '/uploads/{upl_id}'.sub('{' + 'upl_id' + '}', CGI.escape(upl_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] || 'Upload'

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

      new_options = opts.merge(
        :operation => :"UploadsApi.get",
        :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: UploadsApi#get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # create
    # Creates a new upload with the provided properties.
    # @param upload_writable [UploadWritable] 
    # @param [Hash] opts the optional parameters
    # @return [Upload]
    def create(upload_writable, opts = {})
      data, _status_code, _headers = upload_create_with_http_info(upload_writable, opts)
      data
    end

    # create
    # Creates a new upload with the provided properties.
    # @param upload_writable [UploadWritable] 
    # @param [Hash] opts the optional parameters
    # @return [Array<(Upload, Integer, Hash)>] Upload data, response status code and response headers
    def upload_create_with_http_info(upload_writable, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: UploadsApi.upload_create ...'
      end
      # verify the required parameter 'upload_writable' is set
      if @api_client.config.client_side_validation && upload_writable.nil?
        fail ArgumentError, "Missing the required parameter 'upload_writable' when calling UploadsApi.upload_create"
      end
      # resource path
      local_var_path = '/uploads'

      # 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'])
      if !content_type.nil?
          header_params['Content-Type'] = content_type
      end

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

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

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

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

      new_options = opts.merge(
        :operation => :"UploadsApi.upload_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: UploadsApi#upload_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # delete
    # Delete an existing upload. You need only supply the unique identifier that was returned upon upload creation.
    # @param upl_id [String] id of the upload
    # @param [Hash] opts the optional parameters
    # @return [nil]
    def delete(upl_id, opts = {})
      upload_delete_with_http_info(upl_id, opts)
      nil
    end

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

      # resource path
      local_var_path = '/uploads/{upl_id}'.sub('{' + 'upl_id' + '}', CGI.escape(upl_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]

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

      new_options = opts.merge(
        :operation => :"UploadsApi.upload_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: UploadsApi#upload_delete\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # create_export
    # Campaign Exports can help you understand exactly which records in a campaign could not be created. By initiating and retrieving an export, you will get row-by-row errors for your campaign. For a step-by-step walkthrough of creating a campaign and exporting failures, see our [Campaigns Guide](https://help.lob.com/best-practices/launching-your-first-campaign).  Create an export file associated with an upload.
    # @param upl_id [String] ID of the upload
    # @param export_model [ExportModel] 
    # @param [Hash] opts the optional parameters
    # @return [UploadCreateExport]
    def create_export(upl_id, export_model, opts = {})
      data, _status_code, _headers = upload_export_create_with_http_info(upl_id, export_model, opts)
      data
    end

    # create_export
    # Campaign Exports can help you understand exactly which records in a campaign could not be created. By initiating and retrieving an export, you will get row-by-row errors for your campaign. For a step-by-step walkthrough of creating a campaign and exporting failures, see our [Campaigns Guide](https://help.lob.com/best-practices/launching-your-first-campaign).  Create an export file associated with an upload.
    # @param upl_id [String] ID of the upload
    # @param export_model [ExportModel] 
    # @param [Hash] opts the optional parameters
    # @return [Array<(UploadCreateExport, Integer, Hash)>] UploadCreateExport data, response status code and response headers
    def upload_export_create_with_http_info(upl_id, export_model, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: UploadsApi.upload_export_create ...'
      end
      # verify the required parameter 'upl_id' is set
      if @api_client.config.client_side_validation && upl_id.nil?
        fail ArgumentError, "Missing the required parameter 'upl_id' when calling UploadsApi.upload_export_create"
      end
      pattern = Regexp.new(/^upl_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && upl_id !~ pattern
        fail ArgumentError, "invalid value for 'upl_id' when calling UploadsApi.upload_export_create, must conform to the pattern #{pattern}."
      end

      # verify the required parameter 'export_model' is set
      if @api_client.config.client_side_validation && export_model.nil?
        fail ArgumentError, "Missing the required parameter 'export_model' when calling UploadsApi.upload_export_create"
      end
      # resource path
      local_var_path = '/uploads/{upl_id}/exports'.sub('{' + 'upl_id' + '}', CGI.escape(upl_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'])
      # HTTP header 'Content-Type'
      content_type = @api_client.select_header_content_type(['application/json'])
      if !content_type.nil?
          header_params['Content-Type'] = content_type
      end

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

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

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

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

      new_options = opts.merge(
        :operation => :"UploadsApi.upload_export_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: UploadsApi#upload_export_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # upload_file
    # Upload an [audience file](https://help.lob.com/best-practices/campaign-audience-guide) and associate it with an upload.
    # @param upl_id [String] ID of the upload
    # @param file [AnyType] 
    # @param [Hash] opts the optional parameters
    # @return [UploadFile]
    def upload_file(upl_id, file, opts = {})
      data, _status_code, _headers = upload_file_create_with_http_info(upl_id, file, opts)
      data
    end

    # upload_file
    # Upload an [audience file](https://help.lob.com/best-practices/campaign-audience-guide) and associate it with an upload.
    # @param upl_id [String] ID of the upload
    # @param file [AnyType] 
    # @param [Hash] opts the optional parameters
    # @return [Array<(UploadFile, Integer, Hash)>] UploadFile data, response status code and response headers
    def upload_file_create_with_http_info(upl_id, file, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: UploadsApi.upload_file_create ...'
      end
      # verify the required parameter 'upl_id' is set
      if @api_client.config.client_side_validation && upl_id.nil?
        fail ArgumentError, "Missing the required parameter 'upl_id' when calling UploadsApi.upload_file_create"
      end
      pattern = Regexp.new(/^upl_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && upl_id !~ pattern
        fail ArgumentError, "invalid value for 'upl_id' when calling UploadsApi.upload_file_create, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/uploads/{upl_id}/file'.sub('{' + 'upl_id' + '}', CGI.escape(upl_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'])
      # HTTP header 'Content-Type'
      content_type = @api_client.select_header_content_type(['multipart/form-data'])
      if !content_type.nil?
          header_params['Content-Type'] = content_type
      end

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

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

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

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

      new_options = opts.merge(
        :operation => :"UploadsApi.upload_file_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: UploadsApi#upload_file_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # update
    # Update the details of an existing upload. You need only supply the unique identifier that was returned upon upload creation.
    # @param upl_id [String] id of the upload
    # @param upload_updatable [UploadUpdatable] 
    # @param [Hash] opts the optional parameters
    # @return [Upload]
    def update(upl_id, upload_updatable, opts = {})
      data, _status_code, _headers = upload_update_with_http_info(upl_id, upload_updatable, opts)
      data
    end

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

      # verify the required parameter 'upload_updatable' is set
      if @api_client.config.client_side_validation && upload_updatable.nil?
        fail ArgumentError, "Missing the required parameter 'upload_updatable' when calling UploadsApi.upload_update"
      end
      # resource path
      local_var_path = '/uploads/{upl_id}'.sub('{' + 'upl_id' + '}', CGI.escape(upl_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'])
      # HTTP header 'Content-Type'
      content_type = @api_client.select_header_content_type(['application/json'])
      if !content_type.nil?
          header_params['Content-Type'] = content_type
      end

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

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

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

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

      new_options = opts.merge(
        :operation => :"UploadsApi.upload_update",
        :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(:PATCH, local_var_path, new_options)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: UploadsApi#upload_update\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # list
    # Returns a list of your uploads. Optionally, filter uploads by campaign.
    # @param [Hash] opts the optional parameters
    # @option opts [String] :campaign_id id of the campaign
    # @return [Array<Upload>]
    def list(opts = {})
      data, _status_code, _headers = uploads_list_with_http_info(opts)
      data
    end

    # list
    # Returns a list of your uploads. Optionally, filter uploads by campaign.
    # @param [Hash] opts the optional parameters
    # @option opts [String] :campaign_id id of the campaign
    # @return [Array<(Array<Upload>, Integer, Hash)>] Array<Upload> data, response status code and response headers
    def uploads_list_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: UploadsApi.uploads_list ...'
      end
      pattern = Regexp.new(/^cmp_[a-zA-Z0-9]+$/)
      if @api_client.config.client_side_validation && !opts[:'campaign_id'].nil? && opts[:'campaign_id'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"campaign_id\"]' when calling UploadsApi.uploads_list, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/uploads'

      # query parameters
      query_params = opts[:query_params] || {}
      query_params[:'campaignId'] = opts[:'campaign_id'] if !opts[:'campaign_id'].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] || 'Array<Upload>'

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

      new_options = opts.merge(
        :operation => :"UploadsApi.uploads_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: UploadsApi#uploads_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end
