=begin
#User Provisioning

#Add, manage, and remove users from your account

The version of the OpenAPI document: v3

Generated by: https://openapi-generator.tech
OpenAPI Generator version: 6.2.1

=end

require 'cgi'

module Hubspot
  module Settings
    module Users
      class UsersApi
        attr_accessor :api_client

        def initialize(api_client = ApiClient.default)
          @api_client = api_client
        end
        # Removes a user
        # Removes a user identified by `userId`. `userId` refers to the user's ID by default, or optionally email as specified by the `IdProperty` query param.
        # @param user_id [String] Identifier of user to delete
        # @param [Hash] opts the optional parameters
        # @option opts [String] :id_property The name of a property with unique user values. Valid values are &#x60;USER_ID&#x60;(default) or &#x60;EMAIL&#x60;
        # @return [nil]
        def archive(user_id, opts = {})
          archive_with_http_info(user_id, opts)
          nil
        end

        # Removes a user
        # Removes a user identified by &#x60;userId&#x60;. &#x60;userId&#x60; refers to the user&#39;s ID by default, or optionally email as specified by the &#x60;IdProperty&#x60; query param.
        # @param user_id [String] Identifier of user to delete
        # @param [Hash] opts the optional parameters
        # @option opts [String] :id_property The name of a property with unique user values. Valid values are &#x60;USER_ID&#x60;(default) or &#x60;EMAIL&#x60;
        # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
        def archive_with_http_info(user_id, opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: UsersApi.archive ...'
          end
          # verify the required parameter 'user_id' is set
          if @api_client.config.client_side_validation && user_id.nil?
            fail ArgumentError, "Missing the required parameter 'user_id' when calling UsersApi.archive"
          end
          allowable_values = ["USER_ID", "EMAIL"]
          if @api_client.config.client_side_validation && opts[:'id_property'] && !allowable_values.include?(opts[:'id_property'])
            fail ArgumentError, "invalid value for \"id_property\", must be one of #{allowable_values}"
          end
          # resource path
          local_var_path = '/settings/v3/users/{userId}'.sub('{' + 'userId' + '}', CGI.escape(user_id.to_s))

          # query parameters
          query_params = opts[:query_params] || {}
          query_params[:'idProperty'] = opts[:'id_property'] if !opts[:'id_property'].nil?

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

          # 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] || ['oauth2']

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

        # Adds a user
        # New users will only have minimal permissions, which is contacts-base. A welcome email will prompt them to set a password and log in to HubSpot.
        # @param user_provision_request [UserProvisionRequest] 
        # @param [Hash] opts the optional parameters
        # @return [PublicUser]
        def create(user_provision_request, opts = {})
          data, _status_code, _headers = create_with_http_info(user_provision_request, opts)
          data
        end

        # Adds a user
        # New users will only have minimal permissions, which is contacts-base. A welcome email will prompt them to set a password and log in to HubSpot.
        # @param user_provision_request [UserProvisionRequest] 
        # @param [Hash] opts the optional parameters
        # @return [Array<(PublicUser, Integer, Hash)>] PublicUser data, response status code and response headers
        def create_with_http_info(user_provision_request, opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: UsersApi.create ...'
          end
          # verify the required parameter 'user_provision_request' is set
          if @api_client.config.client_side_validation && user_provision_request.nil?
            fail ArgumentError, "Missing the required parameter 'user_provision_request' when calling UsersApi.create"
          end
          # resource path
          local_var_path = '/settings/v3/users/'

          # 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(user_provision_request)

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

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

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

        # Retrieves a user
        # Retrieves a user identified by `userId`. `userId` refers to the user's ID by default, or optionally email as specified by the `IdProperty` query param.
        # @param user_id [String] Identifier of user to retrieve
        # @param [Hash] opts the optional parameters
        # @option opts [String] :id_property The name of a property with unique user values. Valid values are &#x60;USER_ID&#x60;(default) or &#x60;EMAIL&#x60;
        # @return [PublicUser]
        def get_by_id(user_id, opts = {})
          data, _status_code, _headers = get_by_id_with_http_info(user_id, opts)
          data
        end

        # Retrieves a user
        # Retrieves a user identified by &#x60;userId&#x60;. &#x60;userId&#x60; refers to the user&#39;s ID by default, or optionally email as specified by the &#x60;IdProperty&#x60; query param.
        # @param user_id [String] Identifier of user to retrieve
        # @param [Hash] opts the optional parameters
        # @option opts [String] :id_property The name of a property with unique user values. Valid values are &#x60;USER_ID&#x60;(default) or &#x60;EMAIL&#x60;
        # @return [Array<(PublicUser, Integer, Hash)>] PublicUser data, response status code and response headers
        def get_by_id_with_http_info(user_id, opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: UsersApi.get_by_id ...'
          end
          # verify the required parameter 'user_id' is set
          if @api_client.config.client_side_validation && user_id.nil?
            fail ArgumentError, "Missing the required parameter 'user_id' when calling UsersApi.get_by_id"
          end
          allowable_values = ["USER_ID", "EMAIL"]
          if @api_client.config.client_side_validation && opts[:'id_property'] && !allowable_values.include?(opts[:'id_property'])
            fail ArgumentError, "invalid value for \"id_property\", must be one of #{allowable_values}"
          end
          # resource path
          local_var_path = '/settings/v3/users/{userId}'.sub('{' + 'userId' + '}', CGI.escape(user_id.to_s))

          # query parameters
          query_params = opts[:query_params] || {}
          query_params[:'idProperty'] = opts[:'id_property'] if !opts[:'id_property'].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] || 'PublicUser'

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

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

        # Retrieves a list of users from an account
        # Retrieves a list of users from an account
        # @param [Hash] opts the optional parameters
        # @option opts [Integer] :limit The number of users to retrieve
        # @option opts [String] :after Results will display maximum 100 users per page. Additional results will be on the next page.
        # @return [CollectionResponsePublicUserForwardPaging]
        def get_page(opts = {})
          data, _status_code, _headers = get_page_with_http_info(opts)
          data
        end

        # Retrieves a list of users from an account
        # Retrieves a list of users from an account
        # @param [Hash] opts the optional parameters
        # @option opts [Integer] :limit The number of users to retrieve
        # @option opts [String] :after Results will display maximum 100 users per page. Additional results will be on the next page.
        # @return [Array<(CollectionResponsePublicUserForwardPaging, Integer, Hash)>] CollectionResponsePublicUserForwardPaging data, response status code and response headers
        def get_page_with_http_info(opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: UsersApi.get_page ...'
          end
          # resource path
          local_var_path = '/settings/v3/users/'

          # query parameters
          query_params = opts[:query_params] || {}
          query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
          query_params[:'after'] = opts[:'after'] if !opts[:'after'].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] || 'CollectionResponsePublicUserForwardPaging'

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

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

        # Modifies a user
        # Modifies a user identified by `userId`. `userId` refers to the user's ID by default, or optionally email as specified by the `IdProperty` query param.
        # @param user_id [String] Identifier of user to retrieve
        # @param public_user_update [PublicUserUpdate] 
        # @param [Hash] opts the optional parameters
        # @option opts [String] :id_property The name of a property with unique user values. Valid values are &#x60;USER_ID&#x60;(default) or &#x60;EMAIL&#x60;
        # @return [PublicUser]
        def replace(user_id, public_user_update, opts = {})
          data, _status_code, _headers = replace_with_http_info(user_id, public_user_update, opts)
          data
        end

        # Modifies a user
        # Modifies a user identified by &#x60;userId&#x60;. &#x60;userId&#x60; refers to the user&#39;s ID by default, or optionally email as specified by the &#x60;IdProperty&#x60; query param.
        # @param user_id [String] Identifier of user to retrieve
        # @param public_user_update [PublicUserUpdate] 
        # @param [Hash] opts the optional parameters
        # @option opts [String] :id_property The name of a property with unique user values. Valid values are &#x60;USER_ID&#x60;(default) or &#x60;EMAIL&#x60;
        # @return [Array<(PublicUser, Integer, Hash)>] PublicUser data, response status code and response headers
        def replace_with_http_info(user_id, public_user_update, opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: UsersApi.replace ...'
          end
          # verify the required parameter 'user_id' is set
          if @api_client.config.client_side_validation && user_id.nil?
            fail ArgumentError, "Missing the required parameter 'user_id' when calling UsersApi.replace"
          end
          # verify the required parameter 'public_user_update' is set
          if @api_client.config.client_side_validation && public_user_update.nil?
            fail ArgumentError, "Missing the required parameter 'public_user_update' when calling UsersApi.replace"
          end
          allowable_values = ["USER_ID", "EMAIL"]
          if @api_client.config.client_side_validation && opts[:'id_property'] && !allowable_values.include?(opts[:'id_property'])
            fail ArgumentError, "invalid value for \"id_property\", must be one of #{allowable_values}"
          end
          # resource path
          local_var_path = '/settings/v3/users/{userId}'.sub('{' + 'userId' + '}', CGI.escape(user_id.to_s))

          # query parameters
          query_params = opts[:query_params] || {}
          query_params[:'idProperty'] = opts[:'id_property'] if !opts[:'id_property'].nil?

          # 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(public_user_update)

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

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

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