=begin
#qTest Manager API Version 8.6 - 9.1

#qTest Manager API Version 8.6 - 9.1

OpenAPI spec version: 8.6 - 9.1

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

=end

require "uri"

module SwaggerClient
  class DefectApi
    attr_accessor :api_client

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

    # Adds a Comment to a Defect
    # To add a Comment to a Defect  <strong>qTest Manager version:</strong> 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect
    # @param body The Comment&#39;s content
    # @param [Hash] opts the optional parameters
    # @return [CommentResource]
    def add_comment(project_id, id_or_key, body, opts = {})
      data, _status_code, _headers = add_comment_with_http_info(project_id, id_or_key, body, opts)
      return data
    end

    # Adds a Comment to a Defect
    # To add a Comment to a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect
    # @param body The Comment&#39;s content
    # @param [Hash] opts the optional parameters
    # @return [Array<(CommentResource, Fixnum, Hash)>] CommentResource data, response status code and response headers
    def add_comment_with_http_info(project_id, id_or_key, body, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.add_comment ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.add_comment" if project_id.nil?
      # verify the required parameter 'id_or_key' is set
      fail ArgumentError, "Missing the required parameter 'id_or_key' when calling DefectApi.add_comment" if id_or_key.nil?
      # verify the required parameter 'body' is set
      fail ArgumentError, "Missing the required parameter 'body' when calling DefectApi.add_comment" if body.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{idOrKey}/comments".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'idOrKey' + '}', id_or_key.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(body)
      auth_names = ['Authorization']
      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 => 'CommentResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#add_comment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Deletes a Comment of a Defect
    # To delete a specific Comment of a Defect  <strong>qTest Manager version:</strong> 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect whose Comment you want to delete
    # @param comment_id ID of the comment.
    # @param [Hash] opts the optional parameters
    # @return [Object]
    def delete_comment(project_id, id_or_key, comment_id, opts = {})
      data, _status_code, _headers = delete_comment_with_http_info(project_id, id_or_key, comment_id, opts)
      return data
    end

    # Deletes a Comment of a Defect
    # To delete a specific Comment of a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect whose Comment you want to delete
    # @param comment_id ID of the comment.
    # @param [Hash] opts the optional parameters
    # @return [Array<(Object, Fixnum, Hash)>] Object data, response status code and response headers
    def delete_comment_with_http_info(project_id, id_or_key, comment_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.delete_comment ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.delete_comment" if project_id.nil?
      # verify the required parameter 'id_or_key' is set
      fail ArgumentError, "Missing the required parameter 'id_or_key' when calling DefectApi.delete_comment" if id_or_key.nil?
      # verify the required parameter 'comment_id' is set
      fail ArgumentError, "Missing the required parameter 'comment_id' when calling DefectApi.delete_comment" if comment_id.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{idOrKey}/comments/{commentId}".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'idOrKey' + '}', id_or_key.to_s).sub('{' + 'commentId' + '}', comment_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['Authorization']
      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 => 'Object')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#delete_comment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Gets a Comment of a Defect
    # To retrieve a specific Comment of a Defect  <strong>qTest Manager version:</strong> 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect whose comment you want to retrieve
    # @param comment_id ID of the comment
    # @param [Hash] opts the optional parameters
    # @return [CommentResource]
    def get_comment(project_id, id_or_key, comment_id, opts = {})
      data, _status_code, _headers = get_comment_with_http_info(project_id, id_or_key, comment_id, opts)
      return data
    end

    # Gets a Comment of a Defect
    # To retrieve a specific Comment of a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect whose comment you want to retrieve
    # @param comment_id ID of the comment
    # @param [Hash] opts the optional parameters
    # @return [Array<(CommentResource, Fixnum, Hash)>] CommentResource data, response status code and response headers
    def get_comment_with_http_info(project_id, id_or_key, comment_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.get_comment ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.get_comment" if project_id.nil?
      # verify the required parameter 'id_or_key' is set
      fail ArgumentError, "Missing the required parameter 'id_or_key' when calling DefectApi.get_comment" if id_or_key.nil?
      # verify the required parameter 'comment_id' is set
      fail ArgumentError, "Missing the required parameter 'comment_id' when calling DefectApi.get_comment" if comment_id.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{idOrKey}/comments/{commentId}".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'idOrKey' + '}', id_or_key.to_s).sub('{' + 'commentId' + '}', comment_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['Authorization']
      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 => 'CommentResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#get_comment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Gets all Comments of a Defect
    # To retrieve all Comments of a Defect  <strong>qTest Manager version:</strong> 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect whose comments you want to retrieve
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :page By default the first page is returned but you can specify any page number to retrieve objects (default to 1)
    # @option opts [Integer] :page_size The result is paginated. By the default, the number of objects in each page is 100 if this is omitted. You can specify your custom number (up to 999) in this parameter (default to 100)
    # @return [PagedResourceCommentResource]
    def get_comments(project_id, id_or_key, opts = {})
      data, _status_code, _headers = get_comments_with_http_info(project_id, id_or_key, opts)
      return data
    end

    # Gets all Comments of a Defect
    # To retrieve all Comments of a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the Defect whose comments you want to retrieve
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :page By default the first page is returned but you can specify any page number to retrieve objects
    # @option opts [Integer] :page_size The result is paginated. By the default, the number of objects in each page is 100 if this is omitted. You can specify your custom number (up to 999) in this parameter
    # @return [Array<(PagedResourceCommentResource, Fixnum, Hash)>] PagedResourceCommentResource data, response status code and response headers
    def get_comments_with_http_info(project_id, id_or_key, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.get_comments ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.get_comments" if project_id.nil?
      # verify the required parameter 'id_or_key' is set
      fail ArgumentError, "Missing the required parameter 'id_or_key' when calling DefectApi.get_comments" if id_or_key.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{idOrKey}/comments".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'idOrKey' + '}', id_or_key.to_s)

      # query parameters
      query_params = {}
      query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
      query_params[:'pageSize'] = opts[:'page_size'] if !opts[:'page_size'].nil?

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['Authorization']
      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 => 'PagedResourceCommentResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#get_comments\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Gets a Defect
    # To retrieve a Defect  <strong>qTest Manager version:</strong> 6+
    # @param project_id ID of the project
    # @param defect_id ID of the defect.
    # @param [Hash] opts the optional parameters
    # @return [DefectResource]
    def get_defect(project_id, defect_id, opts = {})
      data, _status_code, _headers = get_defect_with_http_info(project_id, defect_id, opts)
      return data
    end

    # Gets a Defect
    # To retrieve a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 6+
    # @param project_id ID of the project
    # @param defect_id ID of the defect.
    # @param [Hash] opts the optional parameters
    # @return [Array<(DefectResource, Fixnum, Hash)>] DefectResource data, response status code and response headers
    def get_defect_with_http_info(project_id, defect_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.get_defect ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.get_defect" if project_id.nil?
      # verify the required parameter 'defect_id' is set
      fail ArgumentError, "Missing the required parameter 'defect_id' when calling DefectApi.get_defect" if defect_id.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{defectId}".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'defectId' + '}', defect_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['Authorization']
      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 => 'DefectResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#get_defect\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Gets recently updated Defects
    # To retrieve Defects which have been recently updated after a specified time
    # @param project_id ID of the project
    # @param start_time The specified time since when the Defects have been updated. It needs to be URL encoded: &lt;em&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSSZ&lt;/em&gt; or &lt;em&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ssZZ&lt;/em&gt;
    # @param [Hash] opts the optional parameters
    # @option opts [String] :end_time Do not support at this time. Use the current time only.
    # @option opts [Integer] :size The result is paginated. By the default, the number of objects in each page is 100. You can specify your custom number in this parameter. The maximum page size is 999. (default to 20)
    # @option opts [Integer] :page By default the first page is returned but you can specify any page number to retrieve objects (default to 1)
    # @return [Array<DefectResource>]
    def get_last_changed(project_id, start_time, opts = {})
      data, _status_code, _headers = get_last_changed_with_http_info(project_id, start_time, opts)
      return data
    end

    # Gets recently updated Defects
    # To retrieve Defects which have been recently updated after a specified time
    # @param project_id ID of the project
    # @param start_time The specified time since when the Defects have been updated. It needs to be URL encoded: &lt;em&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSSZ&lt;/em&gt; or &lt;em&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ssZZ&lt;/em&gt;
    # @param [Hash] opts the optional parameters
    # @option opts [String] :end_time Do not support at this time. Use the current time only.
    # @option opts [Integer] :size The result is paginated. By the default, the number of objects in each page is 100. You can specify your custom number in this parameter. The maximum page size is 999.
    # @option opts [Integer] :page By default the first page is returned but you can specify any page number to retrieve objects
    # @return [Array<(Array<DefectResource>, Fixnum, Hash)>] Array<DefectResource> data, response status code and response headers
    def get_last_changed_with_http_info(project_id, start_time, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.get_last_changed ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.get_last_changed" if project_id.nil?
      # verify the required parameter 'start_time' is set
      fail ArgumentError, "Missing the required parameter 'start_time' when calling DefectApi.get_last_changed" if start_time.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/last-change".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s)

      # query parameters
      query_params = {}
      query_params[:'startTime'] = start_time
      query_params[:'endTime'] = opts[:'end_time'] if !opts[:'end_time'].nil?
      query_params[:'size'] = opts[:'size'] if !opts[:'size'].nil?
      query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['Authorization']
      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 => 'Array<DefectResource>')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#get_last_changed\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Submit a Defect
    # To submit an internal Defect
    # @param project_id ID of the project
    # @param body &lt;em&gt;properties:&lt;/em&gt; a JSONArray of field-value pairs  &lt;em&gt;attachments:&lt;/em&gt; a JSONArray of Attachment objects
    # @param [Hash] opts the optional parameters
    # @return [DefectResource]
    def submit_defect(project_id, body, opts = {})
      data, _status_code, _headers = submit_defect_with_http_info(project_id, body, opts)
      return data
    end

    # Submit a Defect
    # To submit an internal Defect
    # @param project_id ID of the project
    # @param body &lt;em&gt;properties:&lt;/em&gt; a JSONArray of field-value pairs  &lt;em&gt;attachments:&lt;/em&gt; a JSONArray of Attachment objects
    # @param [Hash] opts the optional parameters
    # @return [Array<(DefectResource, Fixnum, Hash)>] DefectResource data, response status code and response headers
    def submit_defect_with_http_info(project_id, body, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.submit_defect ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.submit_defect" if project_id.nil?
      # verify the required parameter 'body' is set
      fail ArgumentError, "Missing the required parameter 'body' when calling DefectApi.submit_defect" if body.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(body)
      auth_names = ['Authorization']
      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 => 'DefectResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#submit_defect\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Updates a Comment of a Defect
    # To update a specific Comment of a Defect  <strong>qTest Manager version:</strong> 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the defect whose comment you want to update
    # @param comment_id ID of the comment
    # @param body Given resource to update a comment.
    # @param [Hash] opts the optional parameters
    # @return [CommentResource]
    def update_comment(project_id, id_or_key, comment_id, body, opts = {})
      data, _status_code, _headers = update_comment_with_http_info(project_id, id_or_key, comment_id, body, opts)
      return data
    end

    # Updates a Comment of a Defect
    # To update a specific Comment of a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 7.5+
    # @param project_id ID of the project
    # @param id_or_key PID or ID of the defect whose comment you want to update
    # @param comment_id ID of the comment
    # @param body Given resource to update a comment.
    # @param [Hash] opts the optional parameters
    # @return [Array<(CommentResource, Fixnum, Hash)>] CommentResource data, response status code and response headers
    def update_comment_with_http_info(project_id, id_or_key, comment_id, body, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.update_comment ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.update_comment" if project_id.nil?
      # verify the required parameter 'id_or_key' is set
      fail ArgumentError, "Missing the required parameter 'id_or_key' when calling DefectApi.update_comment" if id_or_key.nil?
      # verify the required parameter 'comment_id' is set
      fail ArgumentError, "Missing the required parameter 'comment_id' when calling DefectApi.update_comment" if comment_id.nil?
      # verify the required parameter 'body' is set
      fail ArgumentError, "Missing the required parameter 'body' when calling DefectApi.update_comment" if body.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{idOrKey}/comments/{commentId}".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'idOrKey' + '}', id_or_key.to_s).sub('{' + 'commentId' + '}', comment_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(body)
      auth_names = ['Authorization']
      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 => 'CommentResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#update_comment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end

    # Updates a Defect
    # To update a Defect  <strong>qTest Manager version:</strong> 6+
    # @param project_id ID of the project
    # @param defect_id ID of the Defect which needs to be updated.
    # @param body The Defect&#39;s updated properties
    # @param [Hash] opts the optional parameters
    # @return [DefectResource]
    def update_defect(project_id, defect_id, body, opts = {})
      data, _status_code, _headers = update_defect_with_http_info(project_id, defect_id, body, opts)
      return data
    end

    # Updates a Defect
    # To update a Defect  &lt;strong&gt;qTest Manager version:&lt;/strong&gt; 6+
    # @param project_id ID of the project
    # @param defect_id ID of the Defect which needs to be updated.
    # @param body The Defect&#39;s updated properties
    # @param [Hash] opts the optional parameters
    # @return [Array<(DefectResource, Fixnum, Hash)>] DefectResource data, response status code and response headers
    def update_defect_with_http_info(project_id, defect_id, body, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: DefectApi.update_defect ..."
      end
      # verify the required parameter 'project_id' is set
      fail ArgumentError, "Missing the required parameter 'project_id' when calling DefectApi.update_defect" if project_id.nil?
      # verify the required parameter 'defect_id' is set
      fail ArgumentError, "Missing the required parameter 'defect_id' when calling DefectApi.update_defect" if defect_id.nil?
      # verify the required parameter 'body' is set
      fail ArgumentError, "Missing the required parameter 'body' when calling DefectApi.update_defect" if body.nil?
      # resource path
      local_var_path = "/api/v3/projects/{projectId}/defects/{defectId}".sub('{format}','json').sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'defectId' + '}', defect_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(body)
      auth_names = ['Authorization']
      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 => 'DefectResource')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: DefectApi#update_defect\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end
