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

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Create cron job workflow trigger
    # Create a new cron job workflow trigger for a tenant
    # @param tenant [String] The tenant id
    # @param workflow [String] The workflow name
    # @param create_cron_workflow_trigger_request [CreateCronWorkflowTriggerRequest] The input to the cron job workflow trigger
    # @param [Hash] opts the optional parameters
    # @return [CronWorkflows]
    def cron_workflow_trigger_create(tenant, workflow, create_cron_workflow_trigger_request, opts = {})
      data, _status_code, _headers = cron_workflow_trigger_create_with_http_info(tenant, workflow, create_cron_workflow_trigger_request, opts)
      data
    end

    # Create cron job workflow trigger
    # Create a new cron job workflow trigger for a tenant
    # @param tenant [String] The tenant id
    # @param workflow [String] The workflow name
    # @param create_cron_workflow_trigger_request [CreateCronWorkflowTriggerRequest] The input to the cron job workflow trigger
    # @param [Hash] opts the optional parameters
    # @return [Array<(CronWorkflows, Integer, Hash)>] CronWorkflows data, response status code and response headers
    def cron_workflow_trigger_create_with_http_info(tenant, workflow, create_cron_workflow_trigger_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WorkflowRunApi.cron_workflow_trigger_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 WorkflowRunApi.cron_workflow_trigger_create"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WorkflowRunApi.cron_workflow_trigger_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 WorkflowRunApi.cron_workflow_trigger_create, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'workflow' is set
      if @api_client.config.client_side_validation && workflow.nil?
        fail ArgumentError, "Missing the required parameter 'workflow' when calling WorkflowRunApi.cron_workflow_trigger_create"
      end
      # verify the required parameter 'create_cron_workflow_trigger_request' is set
      if @api_client.config.client_side_validation && create_cron_workflow_trigger_request.nil?
        fail ArgumentError, "Missing the required parameter 'create_cron_workflow_trigger_request' when calling WorkflowRunApi.cron_workflow_trigger_create"
      end
      # resource path
      local_var_path = '/api/v1/tenants/{tenant}/workflows/{workflow}/crons'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'workflow' + '}', CGI.escape(workflow.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(create_cron_workflow_trigger_request)

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

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

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

    # Trigger workflow run
    # Schedule a new workflow run for a tenant
    # @param tenant [String] The tenant id
    # @param workflow [String] The workflow name
    # @param schedule_workflow_run_request [ScheduleWorkflowRunRequest] The input to the scheduled workflow run
    # @param [Hash] opts the optional parameters
    # @return [ScheduledWorkflows]
    def scheduled_workflow_run_create(tenant, workflow, schedule_workflow_run_request, opts = {})
      data, _status_code, _headers = scheduled_workflow_run_create_with_http_info(tenant, workflow, schedule_workflow_run_request, opts)
      data
    end

    # Trigger workflow run
    # Schedule a new workflow run for a tenant
    # @param tenant [String] The tenant id
    # @param workflow [String] The workflow name
    # @param schedule_workflow_run_request [ScheduleWorkflowRunRequest] The input to the scheduled workflow run
    # @param [Hash] opts the optional parameters
    # @return [Array<(ScheduledWorkflows, Integer, Hash)>] ScheduledWorkflows data, response status code and response headers
    def scheduled_workflow_run_create_with_http_info(tenant, workflow, schedule_workflow_run_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WorkflowRunApi.scheduled_workflow_run_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 WorkflowRunApi.scheduled_workflow_run_create"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WorkflowRunApi.scheduled_workflow_run_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 WorkflowRunApi.scheduled_workflow_run_create, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'workflow' is set
      if @api_client.config.client_side_validation && workflow.nil?
        fail ArgumentError, "Missing the required parameter 'workflow' when calling WorkflowRunApi.scheduled_workflow_run_create"
      end
      # verify the required parameter 'schedule_workflow_run_request' is set
      if @api_client.config.client_side_validation && schedule_workflow_run_request.nil?
        fail ArgumentError, "Missing the required parameter 'schedule_workflow_run_request' when calling WorkflowRunApi.scheduled_workflow_run_create"
      end
      # resource path
      local_var_path = '/api/v1/tenants/{tenant}/workflows/{workflow}/scheduled'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'workflow' + '}', CGI.escape(workflow.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(schedule_workflow_run_request)

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

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

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

    # Cancel workflow runs
    # Cancel a batch of workflow runs
    # @param tenant [String] The tenant id
    # @param workflow_runs_cancel_request [WorkflowRunsCancelRequest] The input to cancel the workflow runs
    # @param [Hash] opts the optional parameters
    # @return [EventUpdateCancel200Response]
    def workflow_run_cancel(tenant, workflow_runs_cancel_request, opts = {})
      data, _status_code, _headers = workflow_run_cancel_with_http_info(tenant, workflow_runs_cancel_request, opts)
      data
    end

    # Cancel workflow runs
    # Cancel a batch of workflow runs
    # @param tenant [String] The tenant id
    # @param workflow_runs_cancel_request [WorkflowRunsCancelRequest] The input to cancel the workflow runs
    # @param [Hash] opts the optional parameters
    # @return [Array<(EventUpdateCancel200Response, Integer, Hash)>] EventUpdateCancel200Response data, response status code and response headers
    def workflow_run_cancel_with_http_info(tenant, workflow_runs_cancel_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WorkflowRunApi.workflow_run_cancel ...'
      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 WorkflowRunApi.workflow_run_cancel"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WorkflowRunApi.workflow_run_cancel, 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 WorkflowRunApi.workflow_run_cancel, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'workflow_runs_cancel_request' is set
      if @api_client.config.client_side_validation && workflow_runs_cancel_request.nil?
        fail ArgumentError, "Missing the required parameter 'workflow_runs_cancel_request' when calling WorkflowRunApi.workflow_run_cancel"
      end
      # resource path
      local_var_path = '/api/v1/tenants/{tenant}/workflows/cancel'.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(workflow_runs_cancel_request)

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

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

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

    # Trigger workflow run
    # Trigger a new workflow run for a tenant
    # @param workflow [String] The workflow id
    # @param trigger_workflow_run_request [TriggerWorkflowRunRequest] The input to the workflow run
    # @param [Hash] opts the optional parameters
    # @option opts [String] :version The workflow version. If not supplied, the latest version is fetched.
    # @return [WorkflowRun]
    def workflow_run_create(workflow, trigger_workflow_run_request, opts = {})
      data, _status_code, _headers = workflow_run_create_with_http_info(workflow, trigger_workflow_run_request, opts)
      data
    end

    # Trigger workflow run
    # Trigger a new workflow run for a tenant
    # @param workflow [String] The workflow id
    # @param trigger_workflow_run_request [TriggerWorkflowRunRequest] The input to the workflow run
    # @param [Hash] opts the optional parameters
    # @option opts [String] :version The workflow version. If not supplied, the latest version is fetched.
    # @return [Array<(WorkflowRun, Integer, Hash)>] WorkflowRun data, response status code and response headers
    def workflow_run_create_with_http_info(workflow, trigger_workflow_run_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WorkflowRunApi.workflow_run_create ...'
      end
      # verify the required parameter 'workflow' is set
      if @api_client.config.client_side_validation && workflow.nil?
        fail ArgumentError, "Missing the required parameter 'workflow' when calling WorkflowRunApi.workflow_run_create"
      end
      if @api_client.config.client_side_validation && workflow.to_s.length > 36
        fail ArgumentError, 'invalid value for "workflow" when calling WorkflowRunApi.workflow_run_create, the character length must be smaller than or equal to 36.'
      end

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

      # verify the required parameter 'trigger_workflow_run_request' is set
      if @api_client.config.client_side_validation && trigger_workflow_run_request.nil?
        fail ArgumentError, "Missing the required parameter 'trigger_workflow_run_request' when calling WorkflowRunApi.workflow_run_create"
      end
      if @api_client.config.client_side_validation && !opts[:'version'].nil? && opts[:'version'].to_s.length > 36
        fail ArgumentError, 'invalid value for "opts[:"version"]" when calling WorkflowRunApi.workflow_run_create, the character length must be smaller than or equal to 36.'
      end

      if @api_client.config.client_side_validation && !opts[:'version'].nil? && opts[:'version'].to_s.length < 36
        fail ArgumentError, 'invalid value for "opts[:"version"]" when calling WorkflowRunApi.workflow_run_create, the character length must be greater than or equal to 36.'
      end

      # resource path
      local_var_path = '/api/v1/workflows/{workflow}/trigger'.sub('{' + 'workflow' + '}', CGI.escape(workflow.to_s))

      # query parameters
      query_params = opts[:query_params] || {}
      query_params[:'version'] = opts[:'version'] if !opts[:'version'].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']
      # 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(trigger_workflow_run_request)

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

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

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

    # Get workflow run input
    # Get the input for a workflow run.
    # @param tenant [String] The tenant id
    # @param workflow_run [String] The workflow run id
    # @param [Hash] opts the optional parameters
    # @return [Hash<String, Object>]
    def workflow_run_get_input(tenant, workflow_run, opts = {})
      data, _status_code, _headers = workflow_run_get_input_with_http_info(tenant, workflow_run, opts)
      data
    end

    # Get workflow run input
    # Get the input for a workflow run.
    # @param tenant [String] The tenant id
    # @param workflow_run [String] The workflow run id
    # @param [Hash] opts the optional parameters
    # @return [Array<(Hash<String, Object>, Integer, Hash)>] Hash<String, Object> data, response status code and response headers
    def workflow_run_get_input_with_http_info(tenant, workflow_run, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WorkflowRunApi.workflow_run_get_input ...'
      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 WorkflowRunApi.workflow_run_get_input"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WorkflowRunApi.workflow_run_get_input, 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 WorkflowRunApi.workflow_run_get_input, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'workflow_run' is set
      if @api_client.config.client_side_validation && workflow_run.nil?
        fail ArgumentError, "Missing the required parameter 'workflow_run' when calling WorkflowRunApi.workflow_run_get_input"
      end
      if @api_client.config.client_side_validation && workflow_run.to_s.length > 36
        fail ArgumentError, 'invalid value for "workflow_run" when calling WorkflowRunApi.workflow_run_get_input, the character length must be smaller than or equal to 36.'
      end

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

      # resource path
      local_var_path = '/api/v1/tenants/{tenant}/workflow-runs/{workflow-run}/input'.sub('{' + 'tenant' + '}', CGI.escape(tenant.to_s)).sub('{' + 'workflow-run' + '}', CGI.escape(workflow_run.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] || 'Hash<String, Object>'

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

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

    # Replay workflow runs
    # Replays a list of workflow runs.
    # @param tenant [String] The tenant id
    # @param replay_workflow_runs_request [ReplayWorkflowRunsRequest] The workflow run ids to replay
    # @param [Hash] opts the optional parameters
    # @return [ReplayWorkflowRunsResponse]
    def workflow_run_update_replay(tenant, replay_workflow_runs_request, opts = {})
      data, _status_code, _headers = workflow_run_update_replay_with_http_info(tenant, replay_workflow_runs_request, opts)
      data
    end

    # Replay workflow runs
    # Replays a list of workflow runs.
    # @param tenant [String] The tenant id
    # @param replay_workflow_runs_request [ReplayWorkflowRunsRequest] The workflow run ids to replay
    # @param [Hash] opts the optional parameters
    # @return [Array<(ReplayWorkflowRunsResponse, Integer, Hash)>] ReplayWorkflowRunsResponse data, response status code and response headers
    def workflow_run_update_replay_with_http_info(tenant, replay_workflow_runs_request, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: WorkflowRunApi.workflow_run_update_replay ...'
      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 WorkflowRunApi.workflow_run_update_replay"
      end
      if @api_client.config.client_side_validation && tenant.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant" when calling WorkflowRunApi.workflow_run_update_replay, 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 WorkflowRunApi.workflow_run_update_replay, the character length must be greater than or equal to 36.'
      end

      # verify the required parameter 'replay_workflow_runs_request' is set
      if @api_client.config.client_side_validation && replay_workflow_runs_request.nil?
        fail ArgumentError, "Missing the required parameter 'replay_workflow_runs_request' when calling WorkflowRunApi.workflow_run_update_replay"
      end
      # resource path
      local_var_path = '/api/v1/tenants/{tenant}/workflow-runs/replay'.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(replay_workflow_runs_request)

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

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

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