lib/ory/api/identity.ex

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

  alias Ory.Connection
  import Ory.RequestBuilder

  @doc """
  Create multiple identities
  Creates multiple [identities](https://www.ory.sh/docs/kratos/concepts/identity-user-model).  You can also use this endpoint to [import credentials](https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities), including passwords, social sign-in settings, and multi-factor authentication methods.  You can import: Up to 1,000 identities per request Up to 200 identities per request if including plaintext passwords  Avoid importing large batches with plaintext passwords. They can cause timeouts as the passwords need to be hashed before they are stored.  If at least one identity is imported successfully, the response status is 200 OK. If all imports fail, the response is one of the following 4xx errors: 400 Bad Request: The request payload is invalid or improperly formatted. 409 Conflict: Duplicate identities or conflicting data were detected.  If you get a 504 Gateway Timeout: Reduce the batch size Avoid duplicate identities Pre-hash passwords with BCrypt  If the issue persists, contact support.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:body` (PatchIdentitiesBody): 

  ### Returns

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

    request =
      %{}
      |> method(:patch)
      |> url("/admin/identities")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

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

  @doc """
  Create an Identity
  Create an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model).  This endpoint can also be used to [import credentials](https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities) for instance passwords, social sign in configurations or multifactor methods.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:body` (CreateIdentityBody): 

  ### Returns

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

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

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

  @doc """
  Create a Recovery Code
  This endpoint creates a recovery code which should be given to the user in order for them to recover (or activate) their account.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:body` (CreateRecoveryCodeForIdentityBody): 

  ### Returns

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

    request =
      %{}
      |> method(:post)
      |> url("/admin/recovery/code")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

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

  @doc """
  Create a Recovery Link
  This endpoint creates a recovery link which should be given to the user in order for them to recover (or activate) their account.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:return_to` (String.t): 
    - `:body` (CreateRecoveryLinkForIdentityBody): 

  ### Returns

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

    request =
      %{}
      |> method(:post)
      |> url("/admin/recovery/link")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

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

  @doc """
  Delete an Identity
  Calling this endpoint irrecoverably and permanently deletes the [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) given its ID. This action can not be undone. This endpoint returns 204 when the identity was deleted or 404 if the identity was not found.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the identity's ID.
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_identity(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def delete_identity(connection, id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/admin/identities/#{id}")
      |> Enum.into([])

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

  @doc """
  Delete a credential for a specific identity
  Delete an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) credential by its type. You cannot delete passkeys or code auth credentials through this API.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the identity's ID.
  - `type` (String.t): Type is the type of credentials to delete. password CredentialsTypePassword oidc CredentialsTypeOIDC totp CredentialsTypeTOTP lookup_secret CredentialsTypeLookup webauthn CredentialsTypeWebAuthn code CredentialsTypeCodeAuth passkey CredentialsTypePasskey profile CredentialsTypeProfile saml CredentialsTypeSAML link_recovery CredentialsTypeRecoveryLink  CredentialsTypeRecoveryLink is a special credential type linked to the link strategy (recovery flow).  It is not used within the credentials object itself. code_recovery CredentialsTypeRecoveryCode
  - `opts` (keyword): Optional parameters
    - `:identifier` (String.t): Identifier is the identifier of the OIDC/SAML credential to delete. Find the identifier by calling the `GET /admin/identities/{id}?include_credential={oidc,saml}` endpoint.

  ### Returns

  - `{:ok, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_identity_credentials(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def delete_identity_credentials(connection, id, type, opts \\ []) do
    optional_params = %{
      :identifier => :query
    }

    request =
      %{}
      |> method(:delete)
      |> url("/admin/identities/#{id}/credentials/#{type}")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Delete & Invalidate an Identity's Sessions
  Calling this endpoint irrecoverably and permanently deletes and invalidates all sessions that belong to the given Identity.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the identity's ID.
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_identity_sessions(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def delete_identity_sessions(connection, id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/admin/identities/#{id}/sessions")
      |> Enum.into([])

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

  @doc """
  Deactivate a Session
  Calling this endpoint deactivates the specified session. Session data is not deleted.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the session's ID.
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec disable_session(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def disable_session(connection, id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/admin/sessions/#{id}")
      |> Enum.into([])

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

  @doc """
  Extend a Session
  Calling this endpoint extends the given session ID. If `session.earliest_possible_extend` is set it will only extend the session after the specified time has passed.  This endpoint returns per default a 204 No Content response on success. Older Ory Network projects may return a 200 OK response with the session in the body. Returning the session as part of the response will be deprecated in the future and should not be relied upon.  This endpoint ignores consecutive requests to extend the same session and returns a 404 error in those scenarios. This endpoint also returns 404 errors if the session does not exist.  Retrieve the session ID from the `/sessions/whoami` endpoint / `toSession` SDK method.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the session's ID.
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Ory.Model.Session.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec extend_session(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.Session.t} | {:error, Tesla.Env.t}
  def extend_session(connection, id, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/admin/sessions/#{id}/extend")
      |> ensure_body()
      |> Enum.into([])

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

  @doc """
  Get an Identity
  Return an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) by its ID. You can optionally include credentials (e.g. social sign in connections) in the response by using the `include_credential` query parameter.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID must be set to the ID of identity you want to get
  - `opts` (keyword): Optional parameters
    - `:include_credential` ([String.t]): Include Credentials in Response  Include any credential, for example `password` or `oidc`, in the response. When set to `oidc`, This will return the initial OAuth 2.0 Access Token, OAuth 2.0 Refresh Token and the OpenID Connect ID Token if available.

  ### Returns

  - `{:ok, Ory.Model.Identity.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_identity(Tesla.Env.client, String.t, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.Identity.t} | {:error, Tesla.Env.t}
  def get_identity(connection, id, opts \\ []) do
    optional_params = %{
      :include_credential => :query
    }

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

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

  @doc """
  Get Identity JSON Schema
  Return a specific identity schema.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID must be set to the ID of schema you want to get
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, map()}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_identity_schema(Tesla.Env.client, String.t, keyword()) :: {:ok, map()} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def get_identity_schema(connection, id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/schemas/#{id}")
      |> Enum.into([])

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

  @doc """
  Get Session
  This endpoint is useful for:  Getting a session object with all specified expandables that exist in an administrative context.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the session's ID.
  - `opts` (keyword): Optional parameters
    - `:expand` ([String.t]): ExpandOptions is a query parameter encoded list of all properties that must be expanded in the Session. Example - ?expand=Identity&expand=Devices If no value is provided, the expandable properties are skipped.

  ### Returns

  - `{:ok, Ory.Model.Session.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_session(Tesla.Env.client, String.t, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.Session.t} | {:error, Tesla.Env.t}
  def get_session(connection, id, opts \\ []) do
    optional_params = %{
      :expand => :query
    }

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

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

  @doc """
  List Identities
  Lists all [identities](https://www.ory.sh/docs/kratos/concepts/identity-user-model) in the system. Note: filters cannot be combined.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:per_page` (integer()): Deprecated Items per Page  DEPRECATED: Please use `page_token` instead. This parameter will be removed in the future.  This is the number of items per page.
    - `:page` (integer()): Deprecated Pagination Page  DEPRECATED: Please use `page_token` instead. This parameter will be removed in the future.  This value is currently an integer, but it is not sequential. The value is not the page number, but a reference. The next page can be any number and some numbers might return an empty list.  For example, page 2 might not follow after page 1. And even if page 3 and 5 exist, but page 4 might not exist. The first page can be retrieved by omitting this parameter. Following page pointers will be returned in the `Link` header.
    - `:page_size` (integer()): Page Size  This is the number of items per page to return. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:page_token` (String.t): Next Page Token  The next page token. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:consistency` (String.t): Read Consistency Level (preview)  The read consistency level determines the consistency guarantee for reads:  strong (slow): The read is guaranteed to return the most recent data committed at the start of the read. eventual (very fast): The result will return data that is about 4.8 seconds old.  The default consistency guarantee can be changed in the Ory Network Console or using the Ory CLI with `ory patch project --replace '/previews/default_read_consistency_level=\"strong\"'`.  Setting the default consistency level to `eventual` may cause regressions in the future as we add consistency controls to more APIs. Currently, the following APIs will be affected by this setting:  `GET /admin/identities`  This feature is in preview and only available in Ory Network.  ConsistencyLevelUnset  ConsistencyLevelUnset is the unset / default consistency level. strong ConsistencyLevelStrong  ConsistencyLevelStrong is the strong consistency level. eventual ConsistencyLevelEventual  ConsistencyLevelEventual is the eventual consistency level using follower read timestamps.
    - `:ids` ([String.t]): Retrieve multiple identities by their IDs.  This parameter has the following limitations:  Duplicate or non-existent IDs are ignored. The order of returned IDs may be different from the request. This filter does not support pagination. You must implement your own pagination as the maximum number of items returned by this endpoint may not exceed a certain threshold (currently 500).
    - `:credentials_identifier` (String.t): CredentialsIdentifier is the identifier (username, email) of the credentials to look up using exact match. Only one of CredentialsIdentifier and CredentialsIdentifierSimilar can be used.
    - `:preview_credentials_identifier_similar` (String.t): This is an EXPERIMENTAL parameter that WILL CHANGE. Do NOT rely on consistent, deterministic behavior. THIS PARAMETER WILL BE REMOVED IN AN UPCOMING RELEASE WITHOUT ANY MIGRATION PATH.  CredentialsIdentifierSimilar is the (partial) identifier (username, email) of the credentials to look up using similarity search. Only one of CredentialsIdentifier and CredentialsIdentifierSimilar can be used.
    - `:include_credential` ([String.t]): Include Credentials in Response  Include any credential, for example `password` or `oidc`, in the response. When set to `oidc`, This will return the initial OAuth 2.0 Access Token, OAuth 2.0 Refresh Token and the OpenID Connect ID Token if available.
    - `:organization_id` (String.t): List identities that belong to a specific organization.

  ### Returns

  - `{:ok, [%Identity{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_identities(Tesla.Env.client, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, [Ory.Model.Identity.t]} | {:error, Tesla.Env.t}
  def list_identities(connection, opts \\ []) do
    optional_params = %{
      :per_page => :query,
      :page => :query,
      :page_size => :query,
      :page_token => :query,
      :consistency => :query,
      :ids => :query,
      :credentials_identifier => :query,
      :preview_credentials_identifier_similar => :query,
      :include_credential => :query,
      :organization_id => :query
    }

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

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

  @doc """
  Get all Identity Schemas
  Returns a list of all identity schemas currently in use.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:per_page` (integer()): Deprecated Items per Page  DEPRECATED: Please use `page_token` instead. This parameter will be removed in the future.  This is the number of items per page.
    - `:page` (integer()): Deprecated Pagination Page  DEPRECATED: Please use `page_token` instead. This parameter will be removed in the future.  This value is currently an integer, but it is not sequential. The value is not the page number, but a reference. The next page can be any number and some numbers might return an empty list.  For example, page 2 might not follow after page 1. And even if page 3 and 5 exist, but page 4 might not exist. The first page can be retrieved by omitting this parameter. Following page pointers will be returned in the `Link` header.
    - `:page_size` (integer()): Page Size  This is the number of items per page to return. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:page_token` (String.t): Next Page Token  The next page token. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).

  ### Returns

  - `{:ok, [%IdentitySchemaContainer{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_identity_schemas(Tesla.Env.client, keyword()) :: {:ok, [Ory.Model.IdentitySchemaContainer.t]} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def list_identity_schemas(connection, opts \\ []) do
    optional_params = %{
      :per_page => :query,
      :page => :query,
      :page_size => :query,
      :page_token => :query
    }

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

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

  @doc """
  List an Identity's Sessions
  This endpoint returns all sessions that belong to the given Identity.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID is the identity's ID.
  - `opts` (keyword): Optional parameters
    - `:per_page` (integer()): Deprecated Items per Page  DEPRECATED: Please use `page_token` instead. This parameter will be removed in the future.  This is the number of items per page.
    - `:page` (integer()): Deprecated Pagination Page  DEPRECATED: Please use `page_token` instead. This parameter will be removed in the future.  This value is currently an integer, but it is not sequential. The value is not the page number, but a reference. The next page can be any number and some numbers might return an empty list.  For example, page 2 might not follow after page 1. And even if page 3 and 5 exist, but page 4 might not exist. The first page can be retrieved by omitting this parameter. Following page pointers will be returned in the `Link` header.
    - `:page_size` (integer()): Page Size  This is the number of items per page to return. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:page_token` (String.t): Next Page Token  The next page token. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:active` (boolean()): Active is a boolean flag that filters out sessions based on the state. If no value is provided, all sessions are returned.

  ### Returns

  - `{:ok, [%Session{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_identity_sessions(Tesla.Env.client, String.t, keyword()) :: {:ok, [Ory.Model.Session.t]} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def list_identity_sessions(connection, id, opts \\ []) do
    optional_params = %{
      :per_page => :query,
      :page => :query,
      :page_size => :query,
      :page_token => :query,
      :active => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/admin/identities/#{id}/sessions")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  List All Sessions
  Listing all sessions that exist.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:page_size` (integer()): Items per Page  This is the number of items per page to return. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:page_token` (String.t): Next Page Token  The next page token. For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
    - `:active` (boolean()): Active is a boolean flag that filters out sessions based on the state. If no value is provided, all sessions are returned.
    - `:expand` ([String.t]): ExpandOptions is a query parameter encoded list of all properties that must be expanded in the Session. If no value is provided, the expandable properties are skipped.

  ### Returns

  - `{:ok, [%Session{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_sessions(Tesla.Env.client, keyword()) :: {:ok, [Ory.Model.Session.t]} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def list_sessions(connection, opts \\ []) do
    optional_params = %{
      :page_size => :query,
      :page_token => :query,
      :active => :query,
      :expand => :query
    }

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

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

  @doc """
  Patch an Identity
  Partially updates an [identity's](https://www.ory.sh/docs/kratos/concepts/identity-user-model) field using [JSON Patch](https://jsonpatch.com/). The fields `id`, `stateChangedAt` and `credentials` can not be updated using this method.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID must be set to the ID of identity you want to update
  - `opts` (keyword): Optional parameters
    - `:body` ([Ory.Model.JsonPatch.t]): 

  ### Returns

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

    request =
      %{}
      |> method(:patch)
      |> url("/admin/identities/#{id}")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

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

  @doc """
  Update an Identity
  This endpoint updates an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model). The full identity payload, except credentials, is expected. For partial updates, use the [patchIdentity](https://www.ory.sh/docs/reference/api#tag/identity/operation/patchIdentity) operation.  A credential can be provided via the `credentials` field in the request body. If provided, the credentials will be imported and added to the existing credentials of the identity.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `id` (String.t): ID must be set to the ID of identity you want to update
  - `opts` (keyword): Optional parameters
    - `:body` (UpdateIdentityBody): 

  ### Returns

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

    request =
      %{}
      |> method(:put)
      |> url("/admin/identities/#{id}")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

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