# NOTE: This file is auto generated by OpenAPI Generator 7.9.0-SNAPSHOT (https://openapi-generator.tech).
# Do not edit this file manually.

defmodule Nuon.Api.Runners do
  @moduledoc """
  API calls for all endpoints tagged `Runners`.
  """

  alias Nuon.Connection
  import Nuon.RequestBuilder

  @doc """
  cancel runner job
  Cancel a runner job. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_job_id` (String.t): runner job ID
  - `body` (map()): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppRunnerJob.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec cancel_runner_job(Tesla.Env.client, String.t, %{optional(String.t) => }, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppRunnerJob.t} | {:error, Tesla.Env.t}
  def cancel_runner_job(connection, runner_job_id, body, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/v1/runner-jobs/#{runner_job_id}/cancel")
      |> add_param(:body, :body, body)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {202, Nuon.Model.AppRunnerJob},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get a runner
  Return a runner. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_id` (String.t): runner ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppRunner.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.AppRunner.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def get_runner(connection, runner_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runners/#{runner_id}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppRunner},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get runner job
  Return a runner job. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_job_id` (String.t): runner job ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppRunnerJob.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner_job(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppRunnerJob.t} | {:error, Tesla.Env.t}
  def get_runner_job(connection, runner_job_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runner-jobs/#{runner_job_id}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppRunnerJob},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get runner job execution
  Return a runner job execution. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_job_id` (String.t): runner job ID
  - `runner_job_execution_id` (String.t): runner job ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppRunnerJobExecution.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner_job_execution(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppRunnerJobExecution.t} | {:error, Tesla.Env.t}
  def get_runner_job_execution(connection, runner_job_id, runner_job_execution_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runner-jobs/#{runner_job_id}/executions/#{runner_job_execution_id}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppRunnerJobExecution},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get runner job executions
  Return executions for a runner job. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_job_id` (String.t): runner job ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%AppRunnerJobExecution{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner_job_executions(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, [Nuon.Model.AppRunnerJobExecution.t]} | {:error, Tesla.Env.t}
  def get_runner_job_executions(connection, runner_job_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runner-jobs/#{runner_job_id}/executions")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppRunnerJobExecution},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get runner job plan
  Return a plan for a runner job. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_job_id` (String.t): runner job ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, String.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner_job_plan(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, String.t} | {:error, Tesla.Env.t}
  def get_runner_job_plan(connection, runner_job_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runner-jobs/#{runner_job_id}/plan")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, false},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get runner jobs
  Return runner jobs. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_id` (String.t): runner ID
  - `opts` (keyword): Optional parameters
    - `:limit` (integer()): limit of jobs to return
    - `:group` (String.t): job group
    - `:status` (String.t): job status

  ### Returns

  - `{:ok, [%AppRunnerJob{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner_jobs(Tesla.Env.client, String.t, keyword()) :: {:ok, [Nuon.Model.AppRunnerJob.t]} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def get_runner_jobs(connection, runner_id, opts \\ []) do
    optional_params = %{
      :limit => :query,
      :group => :query,
      :status => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/runners/#{runner_id}/jobs")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppRunnerJob},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get runner settings
  Return runner settings for the provided runner. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_id` (String.t): runner ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppRunnerGroupSettings.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_runner_settings(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppRunnerGroupSettings.t} | {:error, Tesla.Env.t}
  def get_runner_settings(connection, runner_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runners/#{runner_id}/settings")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppRunnerGroupSettings},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end

  @doc """
  get a runner's logs
  Runner log retrieval endpoint.  Supports pagination via a header:`X-Nuon-API-Offset`. This header can be passed back to the api and controls the timestamp from which the pagination on the request.  The endpoint returns the offset for the next page in the header: `X-Nuon-API-Next`. To use the next page, use that value in the `X-Nuon-API-Offset` header.  The implicit offset in a request that provides to `X-Nuon-API-Offset` is 0. This returns the first page.  This endpoint accepts two query params: `job_id` and `job_execution_id`. Neither is required. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `runner_id` (String.t): runner ID
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%AppOtelLogRecord{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec otel_read_logs(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, [Nuon.Model.AppOtelLogRecord.t]} | {:error, Tesla.Env.t}
  def otel_read_logs(connection, runner_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/runners/#{runner_id}/logs")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Nuon.Model.AppOtelLogRecord},
      {400, Nuon.Model.StderrErrResponse},
      {401, Nuon.Model.StderrErrResponse},
      {403, Nuon.Model.StderrErrResponse},
      {404, Nuon.Model.StderrErrResponse},
      {500, Nuon.Model.StderrErrResponse}
    ])
  end
end
