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

  alias Nuon.Connection
  import Nuon.RequestBuilder

  @doc """
  Add a user to the current org

  ### Parameters

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

  ### Returns

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

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, 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 """
  create a new org

  ### Parameters

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

  ### Returns

  - `{:ok, Nuon.Model.AppOrg.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_org(Tesla.Env.client, Nuon.Model.ServiceCreateOrgRequest.t, keyword()) :: {:ok, Nuon.Model.AppOrg.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def create_org(connection, service_create_org_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/orgs")
      |> add_param(:body, :body, service_create_org_request)
      |> Enum.into([])

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

  @doc """
  Invite a user to the current org
  Invite a user (by email) to an org.  This user will receive an email, and when they next log into the application will be added to the org. 

  ### Parameters

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

  ### Returns

  - `{:ok, Nuon.Model.AppOrgInvite.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_org_invite(Tesla.Env.client, Nuon.Model.ServiceCreateOrgInviteRequest.t, keyword()) :: {:ok, Nuon.Model.AppOrgInvite.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def create_org_invite(connection, service_create_org_invite_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/orgs/current/invites")
      |> add_param(:body, :body, service_create_org_invite_request)
      |> Enum.into([])

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

  @doc """
  Delete an org

  ### Parameters

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

  ### Returns

  - `{:ok, boolean()}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_org(Tesla.Env.client, keyword()) :: {:ok, Nuon.Model.StderrErrResponse.t} | {:ok, boolean()} | {:error, Tesla.Env.t}
  def delete_org(connection, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/v1/orgs/current")
      |> 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 an org

  ### Parameters

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

  ### Returns

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

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

  @doc """
  Get an org's health checks
  Fetch the most recent health checks for an org. Health checks are automatically performed once every 60 seconds. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:limit` (integer()): limit of health checks to return

  ### Returns

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

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

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

  @doc """
  Return org invites
  Returns a list of all invites to the org. 

  ### Parameters

  - `connection` (Nuon.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:limit` (integer()): limit of health checks to return

  ### Returns

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

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

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

  @doc """
  Get an org's runner group
  Get the current org's runner group, which includes the runners and their settings. 

  ### Parameters

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

  ### Returns

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

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

  @doc """
  Return current user's orgs

  ### Parameters

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

  ### Returns

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

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

  @doc """
  Update current org

  ### Parameters

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

  ### Returns

  - `{:ok, Nuon.Model.AppOrg.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec update_org(Tesla.Env.client, Nuon.Model.ServiceUpdateOrgRequest.t, keyword()) :: {:ok, Nuon.Model.AppOrg.t} | {:ok, Nuon.Model.StderrErrResponse.t} | {:error, Tesla.Env.t}
  def update_org(connection, service_update_org_request, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/v1/orgs/current")
      |> add_param(:body, :body, service_update_org_request)
      |> Enum.into([])

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