# 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.Components do
  @moduledoc """
  API calls for all endpoints tagged `Components`.
  """

  alias Nuon.Connection
  import Nuon.RequestBuilder

  @doc """
  create a component

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `app_id` (String.t): app ID
  - `service_create_component_request` (ServiceCreateComponentRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppComponent.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_component(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateComponentRequest.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppComponent.t} | {:error, Tesla.Env.t}
  def create_component(connection, app_id, service_create_component_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/apps/#{app_id}/components")
      |> add_param(:body, :body, service_create_component_request)
      |> Enum.into([])

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

  @doc """
  create component build

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_create_component_build_request` (ServiceCreateComponentBuildRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppComponentBuild.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_component_build(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateComponentBuildRequest.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppComponentBuild.t} | {:error, Tesla.Env.t}
  def create_component_build(connection, component_id, service_create_component_build_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/components/#{component_id}/builds")
      |> add_param(:body, :body, service_create_component_build_request)
      |> Enum.into([])

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

  @doc """
  create a docker build component config

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_create_docker_build_component_config_request` (ServiceCreateDockerBuildComponentConfigRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppDockerBuildComponentConfig.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_docker_build_component_config(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateDockerBuildComponentConfigRequest.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppDockerBuildComponentConfig.t} | {:error, Tesla.Env.t}
  def create_docker_build_component_config(connection, component_id, service_create_docker_build_component_config_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/components/#{component_id}/configs/docker-build")
      |> add_param(:body, :body, service_create_docker_build_component_config_request)
      |> Enum.into([])

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

  @doc """
  create an external image component config

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_create_external_image_component_config_request` (ServiceCreateExternalImageComponentConfigRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppExternalImageComponentConfig.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_external_image_component_config(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateExternalImageComponentConfigRequest.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppExternalImageComponentConfig.t} | {:error, Tesla.Env.t}
  def create_external_image_component_config(connection, component_id, service_create_external_image_component_config_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/components/#{component_id}/configs/external-image")
      |> add_param(:body, :body, service_create_external_image_component_config_request)
      |> Enum.into([])

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

  @doc """
  create a helm component config

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_create_helm_component_config_request` (ServiceCreateHelmComponentConfigRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppHelmComponentConfig.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_helm_component_config(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateHelmComponentConfigRequest.t, keyword()) :: {:ok, Nuon.Model.AppHelmComponentConfig.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def create_helm_component_config(connection, component_id, service_create_helm_component_config_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/components/#{component_id}/configs/helm")
      |> add_param(:body, :body, service_create_helm_component_config_request)
      |> Enum.into([])

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

  @doc """
  create a job component config

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_create_job_component_config_request` (ServiceCreateJobComponentConfigRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppJobComponentConfig.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_job_component_config(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateJobComponentConfigRequest.t, keyword()) :: {:ok, Nuon.Model.AppJobComponentConfig.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def create_job_component_config(connection, component_id, service_create_job_component_config_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/components/#{component_id}/configs/job")
      |> add_param(:body, :body, service_create_job_component_config_request)
      |> Enum.into([])

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

  @doc """
  create a terraform component config

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_create_terraform_module_component_config_request` (ServiceCreateTerraformModuleComponentConfigRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppTerraformModuleComponentConfig.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_terraform_module_component_config(Tesla.Env.client, String.t, Nuon.Model.ServiceCreateTerraformModuleComponentConfigRequest.t, keyword()) :: {:ok, Nuon.Model.AppTerraformModuleComponentConfig.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def create_terraform_module_component_config(connection, component_id, service_create_terraform_module_component_config_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/components/#{component_id}/configs/terraform-module")
      |> add_param(:body, :body, service_create_terraform_module_component_config_request)
      |> Enum.into([])

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

  @doc """
  delete a component

  ### Parameters

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

  ### Returns

  - `{:ok, boolean()}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_component(Tesla.Env.client, String.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, boolean()} | {:error, Tesla.Env.t}
  def delete_component(connection, component_id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/v1/components/#{component_id}")
      |> 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 a components for a specific app
  Return an app component by id or name. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `app_id` (String.t): app ID
  - `component_name_or_id` (String.t): name or ID
  - `opts` (keyword): Optional parameters

  ### Returns

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

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

  @doc """
  get all components for an app

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get a build
  Returns builds for one or all components in an app. 

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get a component

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get a build for a component
  Returns builds for one or all components in an app. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `build_id` (String.t): build ID
  - `opts` (keyword): Optional parameters

  ### Returns

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

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

  @doc """
  get component build logs

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `build_id` (String.t): build ID
  - `opts` (keyword): Optional parameters

  ### Returns

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

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

  @doc """
  get component build plan

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `build_id` (String.t): build ID
  - `opts` (keyword): Optional parameters

  ### Returns

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

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

  @doc """
  get builds for components

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:limit` (integer()): limit of builds to return
    - `:component_id` (String.t): component id to filter by
    - `:app_id` (String.t): app id to filter by

  ### Returns

  - `{:ok, [%AppComponentBuild{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_component_builds(Tesla.Env.client, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, [Nuon.Model.AppComponentBuild.t]} | {:error, Tesla.Env.t}
  def get_component_builds(connection, opts \\ []) do
    optional_params = %{
      :limit => :query,
      :component_id => :query,
      :app_id => :query
    }

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

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

  @doc """
  get all configs for a component

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get a component's dependencies

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get latest build for a component

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get latest config for a component

  ### Parameters

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

  ### Returns

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

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

  @doc """
  get all components for an org

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `opts` (keyword): Optional parameters

  ### Returns

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

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

  @doc """
  update a component

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `component_id` (String.t): component ID
  - `service_update_component_request` (ServiceUpdateComponentRequest): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Nuon.Model.AppComponent.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec update_component(Tesla.Env.client, String.t, Nuon.Model.ServiceUpdateComponentRequest.t, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, Nuon.Model.AppComponent.t} | {:error, Tesla.Env.t}
  def update_component(connection, component_id, service_update_component_request, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/v1/components/#{component_id}")
      |> add_param(:body, :body, service_update_component_request)
      |> Enum.into([])

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