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

defmodule Ory.Api.Permission do
  @moduledoc """
  API calls for all endpoints tagged `Permission`.
  """

  alias Ory.Connection
  import Ory.RequestBuilder

  @doc """
  Batch check permissions
  To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:"max-depth"` (integer()): 
    - `:body` (BatchCheckPermissionBody): 

  ### Returns

  - `{:ok, Ory.Model.BatchCheckPermissionResult.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec batch_check_permission(Tesla.Env.client, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.BatchCheckPermissionResult.t} | {:error, Tesla.Env.t}
  def batch_check_permission(connection, opts \\ []) do
    optional_params = %{
      :"max-depth" => :query,
      :body => :body
    }

    request =
      %{}
      |> method(:post)
      |> url("/relation-tuples/batch/check")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.BatchCheckPermissionResult},
      {400, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Check a permission
  To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:namespace` (String.t): Namespace of the Relationship
    - `:object` (String.t): Object of the Relationship
    - `:relation` (String.t): Relation of the Relationship
    - `:subject_id` (String.t): SubjectID of the Relationship
    - `:"subject_set.namespace"` (String.t): Namespace of the Subject Set
    - `:"subject_set.object"` (String.t): Object of the Subject Set
    - `:"subject_set.relation"` (String.t): Relation of the Subject Set
    - `:"max-depth"` (integer()): 

  ### Returns

  - `{:ok, Ory.Model.CheckPermissionResult.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec check_permission(Tesla.Env.client, keyword()) :: {:ok, Ory.Model.CheckPermissionResult.t} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def check_permission(connection, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :object => :query,
      :relation => :query,
      :subject_id => :query,
      :"subject_set.namespace" => :query,
      :"subject_set.object" => :query,
      :"subject_set.relation" => :query,
      :"max-depth" => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/relation-tuples/check/openapi")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.CheckPermissionResult},
      {400, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Check a permission
  To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:namespace` (String.t): Namespace of the Relationship
    - `:object` (String.t): Object of the Relationship
    - `:relation` (String.t): Relation of the Relationship
    - `:subject_id` (String.t): SubjectID of the Relationship
    - `:"subject_set.namespace"` (String.t): Namespace of the Subject Set
    - `:"subject_set.object"` (String.t): Object of the Subject Set
    - `:"subject_set.relation"` (String.t): Relation of the Subject Set
    - `:"max-depth"` (integer()): 

  ### Returns

  - `{:ok, Ory.Model.CheckPermissionResult.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec check_permission_or_error(Tesla.Env.client, keyword()) :: {:ok, Ory.Model.CheckPermissionResult.t} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def check_permission_or_error(connection, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :object => :query,
      :relation => :query,
      :subject_id => :query,
      :"subject_set.namespace" => :query,
      :"subject_set.object" => :query,
      :"subject_set.relation" => :query,
      :"max-depth" => :query
    }

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

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.CheckPermissionResult},
      {400, Ory.Model.ErrorGeneric},
      {403, Ory.Model.CheckPermissionResult},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Expand a Relationship into permissions.
  Use this endpoint to expand a relationship tuple into permissions.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `namespace` (String.t): Namespace of the Subject Set
  - `object` (String.t): Object of the Subject Set
  - `relation` (String.t): Relation of the Subject Set
  - `opts` (keyword): Optional parameters
    - `:"max-depth"` (integer()): 

  ### Returns

  - `{:ok, Ory.Model.ExpandedPermissionTree.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec expand_permissions(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.ExpandedPermissionTree.t} | {:error, Tesla.Env.t}
  def expand_permissions(connection, namespace, object, relation, opts \\ []) do
    optional_params = %{
      :"max-depth" => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/relation-tuples/expand")
      |> add_param(:query, :namespace, namespace)
      |> add_param(:query, :object, object)
      |> add_param(:query, :relation, relation)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.ExpandedPermissionTree},
      {400, Ory.Model.ErrorGeneric},
      {404, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Check a permission
  To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:"max-depth"` (integer()): 
    - `:body` (PostCheckPermissionBody): 

  ### Returns

  - `{:ok, Ory.Model.CheckPermissionResult.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec post_check_permission(Tesla.Env.client, keyword()) :: {:ok, Ory.Model.CheckPermissionResult.t} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def post_check_permission(connection, opts \\ []) do
    optional_params = %{
      :"max-depth" => :query,
      :body => :body
    }

    request =
      %{}
      |> method(:post)
      |> url("/relation-tuples/check/openapi")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.CheckPermissionResult},
      {400, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Check a permission
  To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:"max-depth"` (integer()): 
    - `:body` (PostCheckPermissionOrErrorBody): 

  ### Returns

  - `{:ok, Ory.Model.CheckPermissionResult.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec post_check_permission_or_error(Tesla.Env.client, keyword()) :: {:ok, Ory.Model.CheckPermissionResult.t} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def post_check_permission_or_error(connection, opts \\ []) do
    optional_params = %{
      :"max-depth" => :query,
      :body => :body
    }

    request =
      %{}
      |> method(:post)
      |> url("/relation-tuples/check")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.CheckPermissionResult},
      {400, Ory.Model.ErrorGeneric},
      {403, Ory.Model.CheckPermissionResult},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end
end
