# `MishkaCmsCore.Runtime.Resources.Changes.RestoreVersion`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.1/lib/mishka_cms_core/runtime/resources/__changes/restore_version.ex#L5)

Copies a version's snapshot back onto the record it was taken of.

The `:version_id` argument must name one of THIS record's versions. A version of any other record
— another site's included — is refused on `:version_id` with the same words a missing one gets, so
the answer does not say which ids exist elsewhere. Nothing of the refused version reaches the
changeset.

Only the fields the resource's primary `:update` accepts are copied, and never `site_id`: a restore
changes what a record says, not which site it belongs to. Values are cast by each attribute's own
type, so an atom field stored as a string in the snapshot comes back as the atom.

## Options

  * `:version` — the resource's AshPaperTrail version resource. Required. It must have a
    `:get_any` read.

## Usage

    update :restore_version do
      argument :version_id, :uuid, allow_nil?: false

      change {MishkaCmsCore.Runtime.Resources.Changes.RestoreVersion,
              version: MishkaCmsCore.Runtime.Layout.Version}
    end

# `decode`

```elixir
@spec decode(map() | String.t() | nil) :: map()
```

A version's snapshot as a map: `%{}` when it holds none or cannot be read.

# `preview`

```elixir
@spec preview(struct(), module(), map() | String.t() | nil, [atom()] | nil) ::
  struct()
```

`record` as a version's snapshot says it was, for showing and never for saving.

Pass the record, its resource, the version's `changes` (a map, its JSON, or `nil`) and, to name
the fields yourself, the attributes that may be shown (the resource's primary `:update` accepts
by default). A key that is not one of them is left out, and a value stored as text for an
attribute of type `:atom` comes back as the atom, cast by the attribute's own type.

---

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