# `Spectre.Instance.Activation`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/instance/activation.ex#L1)

Canonical snapshot binding one Instance to an active Definition.

Activation is mutable only through generation-fenced compare-and-swap. The
snapshot records the Candidate and publication that were re-read from a
trusted Definition Store, the observed authority epoch, execution closure,
state bindings, owner fencing token, timestamp, and provenance.

# `t`

```elixir
@type t() :: %Spectre.Instance.Activation{
  activated_at: non_neg_integer(),
  activation_receipt: String.t(),
  authority_epoch: non_neg_integer(),
  candidate_ref: Spectre.Definition.Candidate.Ref.t(),
  closure_digest: String.t(),
  definition_ref: Spectre.Definition.Ref.t(),
  generation: pos_integer(),
  manifest_digest: String.t(),
  owner_fencing_token: pos_integer(),
  provenance: map(),
  publication_id: String.t(),
  schema_version: pos_integer(),
  state_bindings: map()
}
```

# `authority_epoch`

```elixir
@spec authority_epoch(t() | nil) :: non_neg_integer()
```

Returns `0` when no Activation exists.

# `build`

```elixir
@spec build(map() | keyword()) :: {:ok, t()} | {:error, term()}
```

Builds and validates an Activation from normalized attributes.

# `compare_and_swap`

```elixir
@spec compare_and_swap(t() | nil, non_neg_integer(), t()) ::
  {:ok, t()} | {:error, term()}
```

Applies an activation generation compare-and-swap.

`expected_generation` is `0` before the first activation. Authority epochs
may stay equal or increase; they can never move backwards.

# `decode`

```elixir
@spec decode(binary()) :: {:ok, t()} | {:error, term()}
```

Decodes and verifies portable Activation bytes.

# `encode`

```elixir
@spec encode(t()) :: {:ok, binary()} | {:error, term()}
```

Encodes the Activation into portable canonical bytes.

# `from_data`

```elixir
@spec from_data(map()) :: {:ok, t()} | {:error, term()}
```

Restores and verifies an Activation from decoded canonical data.

# `generation`

```elixir
@spec generation(t() | nil) :: non_neg_integer()
```

Returns `0` when no Activation exists.

# `new`

```elixir
@spec new(Spectre.Definition.Candidate.t(), map(), keyword()) ::
  {:ok, t()} | {:error, term()}
```

Builds a prospective Activation from a Candidate and verified resolution.

This function does not commit the snapshot. Callers must pass it through
`compare_and_swap/3` on the Instance sequencer.

# `schema_version`

```elixir
@spec schema_version() :: pos_integer()
```

Returns the Activation snapshot schema version.

# `to_data`

```elixir
@spec to_data(t()) :: map()
```

Returns portable canonical data.

---

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