defmodule Ash.Resource.ManualDestroy do
@moduledoc """
A module to implement manual destroy actions.
Note that in the returns of these functions you must return the destroyed record or records.
"""
@type context :: %{
optional(:actor) => term,
optional(:tenant) => term,
optional(:authorize?) => boolean,
optional(:api) => module,
optional(any) => any
}
@callback destroy(
changeset :: Ash.Changeset.t(),
opts :: Keyword.t(),
context :: context()
) ::
{:ok, Ash.Resource.record()}
| {:ok, Ash.Resource.record(), list(Ash.Notifier.Notification.t())}
| {:error, term}
@callback bulk_destroy(
changesets :: Enumerable.t(Ash.Changeset.t()),
opts :: Keyword.t(),
context :: context()
) ::
list(
{:ok, Ash.Resource.record()}
| {:error, Ash.Error.t()}
| {:notifications, list(Ash.Notifier.Notification.t())}
)
@optional_callbacks [bulk_destroy: 3]
defmacro __using__(_) do
quote do
@behaviour Ash.Resource.ManualDestroy
end
end
end