=begin
#Daytona

#Daytona AI platform API Docs

The version of the OpenAPI document: 1.0
Contact: support@daytona.com
Generated by: https://openapi-generator.tech
Generator version: 7.21.0

=end

require 'cgi'

module DaytonaApiClient
  class JobsApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Get job details
    # @param job_id [String] ID of the job
    # @param [Hash] opts the optional parameters
    # @return [Job]
    def get_job(job_id, opts = {})
      data, _status_code, _headers = get_job_with_http_info(job_id, opts)
      data
    end

    # Get job details
    # @param job_id [String] ID of the job
    # @param [Hash] opts the optional parameters
    # @return [Array<(Job, Integer, Hash)>] Job data, response status code and response headers
    def get_job_with_http_info(job_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: JobsApi.get_job ...'
      end
      # verify the required parameter 'job_id' is set
      if @api_client.config.client_side_validation && job_id.nil?
        fail ArgumentError, "Missing the required parameter 'job_id' when calling JobsApi.get_job"
      end
      # resource path
      local_var_path = '/jobs/{jobId}'.sub('{' + 'jobId' + '}', CGI.escape(job_id.to_s))

      # query parameters
      query_params = opts[:query_params] || {}

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json']) 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] || 'Job'

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

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

    # List jobs for the runner
    # Returns a paginated list of jobs for the runner, optionally filtered by status.
    # @param [Hash] opts the optional parameters
    # @option opts [Float] :page Page number of the results (default to 1)
    # @option opts [Float] :limit Maximum number of jobs to return (default: 100, max: 500) (default to 100)
    # @option opts [JobStatus] :status Filter jobs by status
    # @option opts [Float] :offset Number of jobs to skip for pagination (default: 0)
    # @return [PaginatedJobs]
    def list_jobs(opts = {})
      data, _status_code, _headers = list_jobs_with_http_info(opts)
      data
    end

    # List jobs for the runner
    # Returns a paginated list of jobs for the runner, optionally filtered by status.
    # @param [Hash] opts the optional parameters
    # @option opts [Float] :page Page number of the results (default to 1)
    # @option opts [Float] :limit Maximum number of jobs to return (default: 100, max: 500) (default to 100)
    # @option opts [JobStatus] :status Filter jobs by status
    # @option opts [Float] :offset Number of jobs to skip for pagination (default: 0)
    # @return [Array<(PaginatedJobs, Integer, Hash)>] PaginatedJobs data, response status code and response headers
    def list_jobs_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: JobsApi.list_jobs ...'
      end
      if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'] < 1
        fail ArgumentError, 'invalid value for "opts[:"page"]" when calling JobsApi.list_jobs, must be greater than or equal to 1.'
      end

      if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 200
        fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling JobsApi.list_jobs, must be smaller than or equal to 200.'
      end

      if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1
        fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling JobsApi.list_jobs, must be greater than or equal to 1.'
      end

      # resource path
      local_var_path = '/jobs'

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

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

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

    # Long poll for jobs
    # Long poll endpoint for runners to fetch pending jobs. Returns immediately if jobs are available, otherwise waits up to timeout seconds.
    # @param [Hash] opts the optional parameters
    # @option opts [Float] :timeout Timeout in seconds for long polling (default: 30, max: 60)
    # @option opts [Float] :limit Maximum number of jobs to return (default: 10, max: 100)
    # @return [PollJobsResponse]
    def poll_jobs(opts = {})
      data, _status_code, _headers = poll_jobs_with_http_info(opts)
      data
    end

    # Long poll for jobs
    # Long poll endpoint for runners to fetch pending jobs. Returns immediately if jobs are available, otherwise waits up to timeout seconds.
    # @param [Hash] opts the optional parameters
    # @option opts [Float] :timeout Timeout in seconds for long polling (default: 30, max: 60)
    # @option opts [Float] :limit Maximum number of jobs to return (default: 10, max: 100)
    # @return [Array<(PollJobsResponse, Integer, Hash)>] PollJobsResponse data, response status code and response headers
    def poll_jobs_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: JobsApi.poll_jobs ...'
      end
      # resource path
      local_var_path = '/jobs/poll'

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

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

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

    # Update job status
    # @param job_id [String] ID of the job
    # @param update_job_status [UpdateJobStatus] 
    # @param [Hash] opts the optional parameters
    # @return [Job]
    def update_job_status(job_id, update_job_status, opts = {})
      data, _status_code, _headers = update_job_status_with_http_info(job_id, update_job_status, opts)
      data
    end

    # Update job status
    # @param job_id [String] ID of the job
    # @param update_job_status [UpdateJobStatus] 
    # @param [Hash] opts the optional parameters
    # @return [Array<(Job, Integer, Hash)>] Job data, response status code and response headers
    def update_job_status_with_http_info(job_id, update_job_status, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: JobsApi.update_job_status ...'
      end
      # verify the required parameter 'job_id' is set
      if @api_client.config.client_side_validation && job_id.nil?
        fail ArgumentError, "Missing the required parameter 'job_id' when calling JobsApi.update_job_status"
      end
      # verify the required parameter 'update_job_status' is set
      if @api_client.config.client_side_validation && update_job_status.nil?
        fail ArgumentError, "Missing the required parameter 'update_job_status' when calling JobsApi.update_job_status"
      end
      # resource path
      local_var_path = '/jobs/{jobId}/status'.sub('{' + 'jobId' + '}', CGI.escape(job_id.to_s))

      # query parameters
      query_params = opts[:query_params] || {}

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json']) 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(update_job_status)

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

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

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