=begin
#Hatchet API

#The Hatchet API

The version of the OpenAPI document: 1.0.0

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

=end

require 'cgi'

module HatchetSdkRest
  class WebhookApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Create a webhook
    # Create a new webhook
    # @param tenant [String] The tenant id
    # @param v1_create_webhook_request [V1CreateWebhookRequest] The input to the webhook creation
    # @param [Hash] opts the optional parameters
    # @return [V1Webhook]
    def v1_webhook_create(tenant, v1_create_webhook_request, opts = {})
      data, _status_code, _headers = v1_webhook_create_with_http_info(tenant, v1_create_webhook_request, opts)
      data
    end

    # Create a webhook
    # Create a new webhook
    # @param tenant [String] The tenant id
    # @param v1_create_webhook_request [V1CreateWebhookRequest] The input to the webhook creation
    # @param [Hash] opts the optional parameters
    # @return [Array<(V1Webhook, Integer, Hash)>] V1Webhook data, response status code and response headers
    def v1_webhook_create_with_http_info(tenant, v1_create_webhook_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WebhookApi.v1_webhook_create ...'
      end
      # verify the required parameter 'tenant' is set
      if @api_client.config.client_side_validation && tenant.nil?
        fail ArgumentError, "Missing the required parameter 'tenant' when calling WebhookApi.v1_webhook_create"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_create, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && tenant.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_create, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'v1_create_webhook_request' is set
      if @api_client.config.client_side_validation && v1_create_webhook_request.nil?
        fail ArgumentError, "Missing the required parameter 'v1_create_webhook_request' when calling WebhookApi.v1_webhook_create"
      end
      # resource path
      local_var_path = '/api/v1/stable/tenants/{tenant}/webhooks'.sub('{' + 'tenant' + '}', CGI.escape(tenant.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']) unless header_params['Accept']
      # 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(v1_create_webhook_request)

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

      # auth_names
      auth_names = opts[:debug_auth_names] || ['cookieAuth', 'bearerAuth']

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

    # Delete a webhook
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The name of the webhook to delete
    # @param [Hash] opts the optional parameters
    # @return [V1Webhook]
    def v1_webhook_delete(tenant, v1_webhook, opts = {})
      data, _status_code, _headers = v1_webhook_delete_with_http_info(tenant, v1_webhook, opts)
      data
    end

    # Delete a webhook
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The name of the webhook to delete
    # @param [Hash] opts the optional parameters
    # @return [Array<(V1Webhook, Integer, Hash)>] V1Webhook data, response status code and response headers
    def v1_webhook_delete_with_http_info(tenant, v1_webhook, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WebhookApi.v1_webhook_delete ...'
      end
      # verify the required parameter 'tenant' is set
      if @api_client.config.client_side_validation && tenant.nil?
        fail ArgumentError, "Missing the required parameter 'tenant' when calling WebhookApi.v1_webhook_delete"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_delete, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && tenant.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_delete, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'v1_webhook' is set
      if @api_client.config.client_side_validation && v1_webhook.nil?
        fail ArgumentError, "Missing the required parameter 'v1_webhook' when calling WebhookApi.v1_webhook_delete"
      end
      # resource path
      local_var_path = '/api/v1/stable/tenants/{tenant}/webhooks/{v1-webhook}'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'v1-webhook' + '}', CGI.escape(v1_webhook.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']) unless header_params['Accept']

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

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

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

      # auth_names
      auth_names = opts[:debug_auth_names] || ['cookieAuth', 'bearerAuth']

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

    # Get a webhook
    # Get a webhook by its name
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The webhook name
    # @param [Hash] opts the optional parameters
    # @return [V1Webhook]
    def v1_webhook_get(tenant, v1_webhook, opts = {})
      data, _status_code, _headers = v1_webhook_get_with_http_info(tenant, v1_webhook, opts)
      data
    end

    # Get a webhook
    # Get a webhook by its name
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The webhook name
    # @param [Hash] opts the optional parameters
    # @return [Array<(V1Webhook, Integer, Hash)>] V1Webhook data, response status code and response headers
    def v1_webhook_get_with_http_info(tenant, v1_webhook, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WebhookApi.v1_webhook_get ...'
      end
      # verify the required parameter 'tenant' is set
      if @api_client.config.client_side_validation && tenant.nil?
        fail ArgumentError, "Missing the required parameter 'tenant' when calling WebhookApi.v1_webhook_get"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_get, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && tenant.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_get, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'v1_webhook' is set
      if @api_client.config.client_side_validation && v1_webhook.nil?
        fail ArgumentError, "Missing the required parameter 'v1_webhook' when calling WebhookApi.v1_webhook_get"
      end
      # resource path
      local_var_path = '/api/v1/stable/tenants/{tenant}/webhooks/{v1-webhook}'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'v1-webhook' + '}', CGI.escape(v1_webhook.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']) unless header_params['Accept']

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

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

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

      # auth_names
      auth_names = opts[:debug_auth_names] || ['cookieAuth', 'bearerAuth']

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

    # List webhooks
    # Lists all webhook for a tenant.
    # @param tenant [String] The tenant id
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :offset The number to skip
    # @option opts [Integer] :limit The number to limit by
    # @option opts [Array<V1WebhookSourceName>] :source_names The source names to filter by
    # @option opts [Array<String>] :webhook_names The webhook names to filter by
    # @return [V1WebhookList]
    def v1_webhook_list(tenant, opts = {})
      data, _status_code, _headers = v1_webhook_list_with_http_info(tenant, opts)
      data
    end

    # List webhooks
    # Lists all webhook for a tenant.
    # @param tenant [String] The tenant id
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :offset The number to skip
    # @option opts [Integer] :limit The number to limit by
    # @option opts [Array<V1WebhookSourceName>] :source_names The source names to filter by
    # @option opts [Array<String>] :webhook_names The webhook names to filter by
    # @return [Array<(V1WebhookList, Integer, Hash)>] V1WebhookList data, response status code and response headers
    def v1_webhook_list_with_http_info(tenant, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WebhookApi.v1_webhook_list ...'
      end
      # verify the required parameter 'tenant' is set
      if @api_client.config.client_side_validation && tenant.nil?
        fail ArgumentError, "Missing the required parameter 'tenant' when calling WebhookApi.v1_webhook_list"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_list, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && tenant.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_list, the character length must be greater than or equal to 36.'
      end

      # resource path
      local_var_path = '/api/v1/stable/tenants/{tenant}/webhooks'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s))

      # query parameters
      query_params = opts[:query_params] || {}
      query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
      query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
      query_params[:'sourceNames'] = @api_client.build_collection_param(opts[:'source_names'], :multi) if !opts[:'source_names'].nil?
      query_params[:'webhookNames'] = @api_client.build_collection_param(opts[:'webhook_names'], :multi) if !opts[:'webhook_names'].nil?

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

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

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

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

      # auth_names
      auth_names = opts[:debug_auth_names] || ['cookieAuth', 'bearerAuth']

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

    # Post a webhook message
    # Post an incoming webhook message
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The webhook name
    # @param [Hash] opts the optional parameters
    # @return [V1WebhookResponse]
    def v1_webhook_receive(tenant, v1_webhook, opts = {})
      data, _status_code, _headers = v1_webhook_receive_with_http_info(tenant, v1_webhook, opts)
      data
    end

    # Post a webhook message
    # Post an incoming webhook message
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The webhook name
    # @param [Hash] opts the optional parameters
    # @return [Array<(V1WebhookResponse, Integer, Hash)>] V1WebhookResponse data, response status code and response headers
    def v1_webhook_receive_with_http_info(tenant, v1_webhook, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WebhookApi.v1_webhook_receive ...'
      end
      # verify the required parameter 'tenant' is set
      if @api_client.config.client_side_validation && tenant.nil?
        fail ArgumentError, "Missing the required parameter 'tenant' when calling WebhookApi.v1_webhook_receive"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_receive, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && tenant.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_receive, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'v1_webhook' is set
      if @api_client.config.client_side_validation && v1_webhook.nil?
        fail ArgumentError, "Missing the required parameter 'v1_webhook' when calling WebhookApi.v1_webhook_receive"
      end
      # resource path
      local_var_path = '/api/v1/stable/tenants/{tenant}/webhooks/{v1-webhook}'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'v1-webhook' + '}', CGI.escape(v1_webhook.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']) unless header_params['Accept']

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

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

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

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

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

    # Update a webhook
    # Update a webhook
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The webhook name
    # @param v1_update_webhook_request [V1UpdateWebhookRequest] The input to the webhook creation
    # @param [Hash] opts the optional parameters
    # @return [V1Webhook]
    def v1_webhook_update(tenant, v1_webhook, v1_update_webhook_request, opts = {})
      data, _status_code, _headers = v1_webhook_update_with_http_info(tenant, v1_webhook, v1_update_webhook_request, opts)
      data
    end

    # Update a webhook
    # Update a webhook
    # @param tenant [String] The tenant id
    # @param v1_webhook [String] The webhook name
    # @param v1_update_webhook_request [V1UpdateWebhookRequest] The input to the webhook creation
    # @param [Hash] opts the optional parameters
    # @return [Array<(V1Webhook, Integer, Hash)>] V1Webhook data, response status code and response headers
    def v1_webhook_update_with_http_info(tenant, v1_webhook, v1_update_webhook_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WebhookApi.v1_webhook_update ...'
      end
      # verify the required parameter 'tenant' is set
      if @api_client.config.client_side_validation && tenant.nil?
        fail ArgumentError, "Missing the required parameter 'tenant' when calling WebhookApi.v1_webhook_update"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_update, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && tenant.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant" when calling WebhookApi.v1_webhook_update, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'v1_webhook' is set
      if @api_client.config.client_side_validation && v1_webhook.nil?
        fail ArgumentError, "Missing the required parameter 'v1_webhook' when calling WebhookApi.v1_webhook_update"
      end
      # verify the required parameter 'v1_update_webhook_request' is set
      if @api_client.config.client_side_validation && v1_update_webhook_request.nil?
        fail ArgumentError, "Missing the required parameter 'v1_update_webhook_request' when calling WebhookApi.v1_webhook_update"
      end
      # resource path
      local_var_path = '/api/v1/stable/tenants/{tenant}/webhooks/{v1-webhook}'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'v1-webhook' + '}', CGI.escape(v1_webhook.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']) unless header_params['Accept']
      # 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(v1_update_webhook_request)

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

      # auth_names
      auth_names = opts[:debug_auth_names] || ['cookieAuth', 'bearerAuth']

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