# `Chronicle.EventSequences.AppendResult`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/event_sequences/append_result.ex#L4)

The detailed outcome of an append, mirroring the .NET client's `AppendResult` /
`AppendManyResult`.

Returned by `Chronicle.EventSequences.EventLog.append_with_result/3` and
`append_many_with_result/3`, which return `{:ok, result}` when the append succeeded and
`{:error, result}` when the kernel rejected it - so a rejection can be inspected instead of
being collapsed into an opaque term.

  * `:sequence_numbers` - the sequence numbers assigned to the appended events, in order
    (empty when nothing was appended or the kernel did not assign any)
  * `:sequence_number` - the first of those, or `nil`
  * `:correlation_id` - the correlation id of the append
  * `:constraint_violations` - list of `t:constraint_violation/0`
  * `:concurrency_violations` - list of `t:concurrency_violation/0`
  * `:errors` - list of error messages

# `concurrency_violation`

```elixir
@type concurrency_violation() :: %{
  event_source_id: String.t(),
  expected_sequence_number: non_neg_integer(),
  actual_sequence_number: non_neg_integer()
}
```

# `constraint_violation`

```elixir
@type constraint_violation() :: %{
  constraint_name: String.t(),
  message: String.t(),
  event_type_id: String.t(),
  sequence_number: non_neg_integer(),
  details: %{optional(String.t()) =&gt; String.t()}
}
```

# `t`

```elixir
@type t() :: %Chronicle.EventSequences.AppendResult{
  client: atom(),
  concurrency_violations: [concurrency_violation()],
  constraint_violations: [constraint_violation()],
  correlation_id: String.t(),
  errors: [String.t()],
  event_sequence_id: String.t(),
  namespace: String.t() | nil,
  sequence_number: non_neg_integer() | nil,
  sequence_numbers: [non_neg_integer()],
  success?: boolean()
}
```

# `rejected?`

```elixir
@spec rejected?(t()) :: boolean()
```

The `Chronicle.Events.EventContext`-free helper: whether any violation was reported.

# `wait_for_completion`

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

Waits for every observer affected by the appended events to reach the last appended
sequence number or fail. Mirrors .NET's `AppendResult.WaitForCompletion()`.

Options: `:timeout` (milliseconds).
Returns `{:ok, %{success: boolean(), failed_partitions: [...]}}`.

---

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