# `Dmn.Model`
[🔗](https://github.com/FeeJai/BDM/blob/dmn-v0.1.0/apps/dmn/lib/dmn/model.ex#L1)

A DMN model as data: the `Definitions` of DMN 1.6 (clause 6.3.2), read from an XML document by `Dmn.Reader`.

The structs follow the metamodel of the specification, and each field is the attribute or the association of the same name in
`snake_case`. They hold what the document says and nothing is decided yet: no name is resolved, no FEEL is read, no
reference is followed. That is `Dmn.Compiler`. A struct that came from an element has its `id` and the `line` of the document.

  * the DRG elements are in lists by kind, each in document order: `decisions`, `input_data`,
    `business_knowledge_models`, `decision_services`, `knowledge_sources`;
  * the expressions of a decision are the structs of `Dmn.Model.Expressions` and `Dmn.Model.DecisionTable`;
  * a reference (`href="#id"`, `href="namespace#id"`) is a `t:Dmn.Model.Reference.t/0`.

| Field | Is |
| ----- | -- |
| `version` | `:dmn_1_1` to `:dmn_1_6`, from the namespace of the document |
| `namespace` | the `namespace` of the definitions, which the elements of the model are in for the other models |
| `expression_language`, `type_language` | the URIs of the defaults of the model (`nil` for FEEL) |
| `imports` | the `Dmn.Model.Import`s |
| `item_definitions` | the `Dmn.Model.ItemDefinition`s |
| `base_uri` | where the document was read from, which a relative `locationURI` of its imports is resolved against (DMN 1.6, 13.3.2; RFC 3986); `nil` if that is not known. **Not in the document**: `Dmn.load/2` takes it as an option, and `Dmn.Imports` sets it for the models it reads, from what the resolver says |
| `sha256` | the SHA-256 of the bytes the model was loaded from (lowercase hex, `digest/1`), or `nil` for a model that was not loaded from bytes. **Not in the document**: `Dmn.load/2` sets it, and it is what `Dmn.Imports` tells the first model by when a model it imports names the namespace of the first one |

# `t`

```elixir
@type t() :: %Dmn.Model{
  base_uri: String.t() | nil,
  business_knowledge_models: [Dmn.Model.BusinessKnowledgeModel.t()],
  decision_services: [Dmn.Model.DecisionService.t()],
  decisions: [Dmn.Model.Decision.t()],
  exporter: String.t() | nil,
  exporter_version: String.t() | nil,
  expression_language: String.t() | nil,
  id: String.t() | nil,
  imports: [Dmn.Model.Import.t()],
  input_data: [Dmn.Model.InputData.t()],
  item_definitions: [Dmn.Model.ItemDefinition.t()],
  knowledge_sources: [Dmn.Model.KnowledgeSource.t()],
  label: String.t() | nil,
  line: pos_integer() | nil,
  name: String.t(),
  namespace: String.t(),
  sha256: String.t() | nil,
  type_language: String.t() | nil,
  version: version()
}
```

# `version`

```elixir
@type version() :: :dmn_1_1 | :dmn_1_2 | :dmn_1_3 | :dmn_1_4 | :dmn_1_5 | :dmn_1_6
```

# `digest`

```elixir
@spec digest(binary()) :: String.t()
```

The SHA-256 of the bytes of a document, in lowercase hex: how a model is told from another one with the same namespace.

    iex> Dmn.Model.digest("")
    "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

# `drg_elements`

```elixir
@spec drg_elements(t()) :: [
  Dmn.Model.Decision.t()
  | Dmn.Model.InputData.t()
  | Dmn.Model.BusinessKnowledgeModel.t()
  | Dmn.Model.DecisionService.t()
  | Dmn.Model.KnowledgeSource.t()
]
```

The DRG elements of every kind, in the order of the kinds above and the document within a kind.

---

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