# `Spectre.Operation.Delivery.Consent`
[🔗](https://github.com/elchemista/spectre/blob/0.3.0/lib/spectre/operation/delivery/consent.ex#L1)

Revocable, expiring consent for proactive delivery to one destination.

# `t`

```elixir
@type t() :: %Spectre.Operation.Delivery.Consent{
  channels: term(),
  destination: term(),
  expires_at: term(),
  granted_at: term(),
  id: term(),
  metadata: term(),
  origin: term(),
  revoked_at: term(),
  subject_id: term()
}
```

# `active?`

```elixir
@spec active?(t(), non_neg_integer()) :: boolean()
```

Returns `true` when the consent is neither revoked nor expired at `now`
(milliseconds); `false` otherwise, including for a non-integer `now`.

# `new`

```elixir
@spec new(t() | map() | keyword()) :: t()
```

Builds a validated consent from a struct, map or keyword list.

Missing `id` and `granted_at` default to a fresh UUIDv7 and the current time.
Raises `ArgumentError` when the resulting consent is invalid.

# `revoke`

```elixir
@spec revoke(t(), non_neg_integer()) :: t()
```

Revokes the consent at `at` (milliseconds), returning the updated consent.

Idempotent: an already revoked consent is returned unchanged. Raises
`ArgumentError` when the revocation time precedes the grant time.

# `validate`

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

Validates the consent's identity, timestamps, channels and portability.

Returns `:ok`, or `{:error, reason}` naming the first invalid field.

---

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