# `ExCEP.Model.Catalog`

Built-in standard device modeling catalog from CSG CEP **TS2.1**
(Chapter 6 Tables 1–26 & Appendix A).

Covers all **5 domains**, **26 standard device models**, **168 logical nodes**
(e.g. `SlrBrkMMXU`, `SlrInvMMXU`, `StoBatMMXU`, `ChgPilZBAT`, `WndFanMMXU`, `TtuLinMMXU`),
and **1,395 standard Data Objects (DOs)** with CDC types, mandatory/optional (`M`/`O`) flags,
and Chinese semantic descriptions.

Loaded lazily from `priv/ts21_catalog.json` and cached in `:persistent_term` for O(1) reads.

# `domain`

```elixir
@type domain() :: :solar | :storage | :charging | :wind | :distribution
```

# `build_model`

```elixir
@spec build_model(domain() | String.t(), atom() | String.t(), keyword()) ::
  {:ok, ExCEP.Model.t()} | {:error, term()}
```

Generates a TS2.1-compliant `%ExCEP.Model{}` directly from a standard catalog device template
(e.g. `Catalog.build_model(:solar, :grid_breaker, model: "CSG_BRK01_J_V1.00")`).

## Options
- `:model` - TS2.1 model name (default `"CSG_<DEV>_J_V1.00"`)
- `:manufacturer_id` - 1..6 char vendor code (default `"CSG"`)
- `:manufacturer_desc` - vendor description (default `"南方电网"`)
- `:dev_type` - 1..12 char device type (default derived from `device`)
- `:version` - version string (default `"V1.00"`)
- `:ld_name` - Logical Device name, 1..6 chars (default `"MEAS"`)
- `:mandatory_only` - include only `M` (mandatory) DOs (default `false`)

# `check_mandatory_points`

```elixir
@spec check_mandatory_points(
  ExCEP.Model.t(),
  domain() | String.t(),
  atom() | String.t()
) ::
  :ok | {:error, term()}
```

Checks whether `%ExCEP.Model{}` includes all mandatory (`M`) Data Objects specified by
TS2.1 Appendix A for `{domain, device}`.

Returns `:ok` or `{:error, {:missing_mandatory_dos, [{ln_name, do_name, description}]}}`.

# `domains`

```elixir
@spec domains() :: [domain()]
```

Returns the 5 standard TS2.1 domains.

# `get_device`

```elixir
@spec get_device(domain() | String.t(), atom() | String.t()) ::
  {:ok, map()} | {:error, :not_found}
```

Fetches a device model definition by `{domain, device}` (e.g. `:solar, :grid_breaker`).

# `get_logical_node`

```elixir
@spec get_logical_node(String.t()) :: {:ok, map()} | {:error, :not_found}
```

Fetches a standard TS2.1 Logical Node definition and all its Appendix A Data Objects
by LN name (e.g. `"SlrBrkMMXU"`, `"StoBatMMXU"`, `"TtuLinMMXU"`).

# `list_devices`

```elixir
@spec list_devices(domain() | String.t() | nil) :: [map()]
```

Lists all 26 standard TS2.1 device model definitions (optionally filtered by `domain`).

# `list_logical_nodes`

```elixir
@spec list_logical_nodes() :: [String.t()]
```

Returns all 168 logical node names in the TS2.1 catalog.

# `list_logical_nodes`

```elixir
@spec list_logical_nodes(domain() | String.t(), atom() | String.t()) ::
  {:ok, [map()]} | {:error, :not_found}
```

Returns the logical node maps belonging to `{domain, device}`.

# `search_dos`

```elixir
@spec search_dos(String.t()) :: [map()]
```

Searches all 1,395 standard TS2.1 Data Objects by substring match against `do_name`,
`full_name`, `description` (Chinese), or `ln_name`.

---

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