# `AshHooks.InboundDelivery.LegacyAdoption`
[🔗](https://github.com/baselabs/ash_hooks/blob/v3.3.0/lib/ash_hooks/inbound_delivery/legacy_adoption.ex#L1)

Plans and applies adoption of provider-defined inbound identities.

This is an explicit upgrade operation for rows created by the former raw
body digest default. It never changes declarations with a host `event_id`
extractor, never guesses an identity for an unavailable payload, and never
processes a delivery. The caller must quiesce ingress and reapers before
applying the reviewed plan.

# `audit_row`

```elixir
@type audit_row() :: %{
  before_key: map(),
  after_key: map(),
  before_external_event_id: String.t(),
  after_external_event_id: String.t(),
  before_status: atom(),
  after_status: atom(),
  payload_digest: String.t(),
  canonical_event_id: String.t(),
  representative: boolean(),
  representative_key: map()
}
```

# `plan`

```elixir
@type plan() :: %{
  provider: atom(),
  scope: map(),
  tenant: term(),
  groups: [map()],
  audit: [audit_row()],
  unresolved: [map()],
  conflicts: [map()]
}
```

# `apply`

```elixir
@spec apply(module(), atom(), keyword()) :: {:ok, plan()} | {:error, term()}
```

Applies a reviewed adoption transaction for one provider/scope/tenant partition.

`quiesced?: true` is mandatory. Any unresolved payload or canonical target
conflict blocks the entire transaction. The resource data layer must support
transactions; otherwise this returns `{:error, :transactions_not_supported}`
before applying the plan. Each sibling remains stored with its original
payload and digest but becomes terminal `:superseded`; the chosen representative
receives the canonical provider identity and keeps its prior processing class.
Use the same `:scope`, `:tenant`, and `:canonical_ids` reviewed through `plan/3`.

# `plan`

```elixir
@spec plan(module(), atom(), keyword()) :: {:ok, plan()} | {:error, term()}
```

Builds a payload-free audit plan without changing any row.

Pass the declaration's exact `:scope` map and, for attribute-multitenant
ledgers, `:tenant`. `:canonical_ids` may map a legacy external event ID to
an explicitly recovered canonical ID for a missing or redacted payload.
The result lists every proposed before/after key, identity, status, selected
representative, unresolved row, and target conflict.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
