# `SefazNfe.EPEC`
[🔗](https://github.com/devaction-labs/sefaz_nfe/blob/v0.5.0/lib/sefaz_nfe/epec.ex#L1)

Reads, from an NF-e issued in EPEC contingency (`tpEmis` 4), the fields the
EPEC event (110140) copies from it.

The document is only read, never modified or re-serialised: it is later
transmitted to the origin authorizer byte for byte, and the EPEC event
registered at the Ambiente Nacional has to agree with it value for value.
Nothing is calculated; `vNF`, `vICMS` and `vST` are the NF-e's own text.

Reads go through `SefazNfe.XML`, scoped to the element that owns the field
(`ide`, `emit`, `dest`, `ICMSTot`), so a same-named element elsewhere in the
document cannot be picked up.

# `dest_id`

```elixir
@type dest_id() :: {:cnpj | :cpf | :id_estrangeiro, String.t()}
```

# `t`

```elixir
@type t() :: %{
  ch_nfe: String.t(),
  tax_id: String.t(),
  epec: %{
    c_uf: String.t(),
    ver_aplic: String.t(),
    dh_emi: String.t(),
    tp_nf: String.t(),
    ie: String.t(),
    dest_uf: String.t(),
    dest_id: dest_id(),
    dest_ie: String.t() | nil,
    v_nf: String.t(),
    v_icms: String.t(),
    v_st: String.t()
  }
}
```

# `extract`

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

The EPEC facts of `xml`, or the reason it cannot be the subject of one.

Errors, all before the network:

  * `{:unsupported_for_model, 65}` and `{:unsupported_model, mod}`: EPEC here
    is for model 55;
  * `{:not_epec_document, tp_emis}`: the document is not `tpEmis` 4;
  * `{:epec, :missing_dest}`: EPEC requires a destinatário;
  * `{:epec, {:missing, element}}`: a field the event copies is absent;
  * `{:epec, {:ch_nfe_uf_mismatch, key_uf, c_uf}}`: the first two digits of
    the access key are not `cUF`;
  * `:invalid_ch_nfe`, `:invalid_tax_id`, `{:xml, _}`.

`:ver_aplic` overrides the `verProc` the event declares.

---

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