# `Statifier.Send.Event`
[🔗](https://github.com/riddler/statifier-ex/blob/v2.6.0/lib/statifier/send/event.ex#L1)

Builds the event a `<send>` delivers, from the send effect the core
produced (ADR-0069 decision 4). Pure: no process, no clock, no lookup.

`build/3` is the one construction site. `Statifier.Session` calls it for
every event a built-in `<send>` delivers to an external queue, and hands
its result to a registered processor (`Statifier.Send.Processor`) for a
send of a registered type. A host that drives `Statifier.Interpreter`
with no session reads the effect off the core and calls it itself.

What it stamps, per spec 5.10.1 and C.1:

  - `name` is the send's `event`, and `data` its resolved payload;
  - `sendid` is the send id only when the author wrote `id` or
    `idlocation` on the `<send>` (the effect's `id_from_author?`), and
    `nil` otherwise - C.1's empty-`sendid` rule;
  - `caller_context` is a delayed send's opaque host term (ADR-0063),
    and `nil` for an immediate send, which carries none;
  - `origin` defaults to the sender's `#_scxml_<sessionid>` location and
    `origintype` to the SCXML Event I/O Processor URI.

A processor with its own reply address passes `:origin` and
`:origintype`, so a receiver that answers "via the Event I/O Processor
specified in 'origintype'" (5.10.1) reaches that processor rather than
the sender's session.

## Why the default `origintype` is the URI

C.1's prose says the field MUST have the value `"scxml"`. The W3C
conformance suite requires the URI instead: test198 sends with no `type`
attribute and asserts `_event.origintype ==
'http://www.w3.org/TR/scxml/#SCXMLEventProcessor'`, test352 asserts the
same for an explicitly typed send, and test253 accepts either spelling.
No test in the corpus requires `"scxml"`. The default follows the suite.
It is the URI whatever `type` the author wrote, so `<send type="scxml">`
also reports the URI where 5.10.1's "equivalent to the 'type' field on
the `<send>` element" would echo `"scxml"`; test253 accepts both and
nothing else covers it.

# `option`

```elixir
@type option() :: {:origin, String.t()} | {:origintype, String.t()}
```

`build/3`'s options: `:origin` (a URI string) and `:origintype` (a type
string), each replacing its default when given.

# `build`

```elixir
@spec build(
  send :: Statifier.Effect.Send.t() | Statifier.Effect.SendDelayed.t(),
  session_id :: String.t(),
  opts :: [option()]
) :: Statifier.Event.t()
```

The `%Statifier.Event{}` that `send` delivers, sent by the session
`session_id` (spec 5.10's `_sessionid`). See the moduledoc for each
field.

## Examples

    iex> send = %Statifier.Effect.Send{
    ...>   event: "impression.joined",
    ...>   data: %{"impression_id" => "imp-1"},
    ...>   send_id: "send_1",
    ...>   macrostep: 0,
    ...>   microstep: 0,
    ...>   round: 0
    ...> }
    iex> event = Statifier.Send.Event.build(send, "sess_1")
    iex> {event.name, event.data, event.sendid, event.origin}
    {"impression.joined", %{"impression_id" => "imp-1"}, nil, "#_scxml_sess_1"}
    iex> event = Statifier.Send.Event.build(send, "sess_1", origin: "myapp:reply/7", origintype: "myapp:execution")
    iex> {event.origin, event.origintype}
    {"myapp:reply/7", "myapp:execution"}

---

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