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

  alias Nuon.Connection
  import Nuon.RequestBuilder

  @doc """
  Get config for cli

  ### Parameters

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

  ### Returns

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

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

  @doc """
  Get regions for a cloud platform
  Return region metadata for the Nuon supported cloud platforms. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `cloud_platform` (String.t): cloud platform
  - `opts` (keyword): Optional parameters

  ### Returns

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

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

  @doc """
  Get jsonschema for config file
  Return jsonschemas for Nuon configs. These can be used in frontmatter in most editors that have a TOML LSP (such as [Taplo](https://taplo.tamasfe.dev/) configured.  ```toml #:schema https://api.nuon.co/v1/general/config-schema?source=inputs  description = \"description\" ```  You can pass in a valid source argument to render within a specific source file:  - input - installer - sandbox - runner - docker_build - container_image - helm - terraform - job  By default, the config expects that you are using multiple files and sources. If you are _not_, then pass the `?flat=true` param. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:source` (String.t): return a schema for a source file
    - `:flat` (String.t): return a flat schema for the full app

  ### Returns

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

    request =
      %{}
      |> method(:get)
      |> url("/v1/general/config-schema")
      |> add_optional_params(optional_params, opts)
      |> 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 current user

  ### Parameters

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

  ### Returns

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

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

  @doc """
  Publish a metric from different Nuon clients for telemetry purposes.

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `service_publish_metric_input` ([Nuon.Model.ServicePublishMetricInput.t]): Input
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, String.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec publish_metrics(Tesla.Env.client, list(Nuon.Model.ServicePublishMetricInput.t), keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, String.t} | {:error, Tesla.Env.t}
  def publish_metrics(connection, service_publish_metric_input, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/general/metrics")
      |> add_param(:body, :body, service_publish_metric_input)
      |> 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
end
