# Catalog Specification

A SimHealth dictionary is a declarative catalog containing synthetic data rules, discrete sets, probabilistic distributions, and identity sequences. Catalogs are scoped to projects and compiled to an internal execution graph.

> [!IMPORTANT]
> Catalogs are strictly validated upon submission. A catalog pack must compile without cycles, undefined references, or unresolved fragment dependencies before it can be activated.

## The four catalog kinds

Every definition in a dictionary belongs to exactly one of the four primitive kinds:

| Kind | Role | Description |
| --- | --- | --- |
| `records` | Entities & Fragments | Defines root record schemas and reusable fragment components. Root records can be sampled directly. |
| `sets` | Discrete Categoricals | Plain text lists of allowable values (e.g. blood types, cities, medication names). One entry per line. |
| `distributions` | Probabilistic Weights | Mathematical distributions and discrete probability tables (`P(name)`) for counts, lengths, and continuous values. |
| `sequences` | Identifiers | Monotonically increasing or template-formatted unique identity generators (e.g. `{n:06}`). |

## Catalog syntax grammar

Definitions use a clean, whitespace-delimited DSL format:

```text
# Sets define discrete pools of values
Set(bloodType)
A+
A-
B+
B-
O+
O-
AB+
AB-

# Distributions define probabilities
P(admissionSeverity)
Emergency    0.15
Urgent       0.35
Elective     0.50

# Sequences format sequential keys
Seq(mrnCounter)
MRN-{n:08}

# Records assemble properties and foreign keys
Record(patient)
mrn          1       Seq(mrnCounter)
bloodType    1       Set(bloodType)
severity     1       P(admissionSeverity)
```

## Batch publishing

Catalog updates can be applied individually with `PUT /v1/projects/{project_id}/catalog/{kind}/{id}` or as an atomic batch update with `POST /v1/projects/{project_id}/catalog/batch`:

```json
{
  "entries": [
    {
      "kind": "sets",
      "id": "statusCodes",
      "source": "Set(statusCodes)\nactive\npending\narchived\n"
    },
    {
      "kind": "records",
      "id": "account",
      "source": "Record(account)\nid 1 Seq(accountId)\nstatus 1 Set(statusCodes)\n"
    }
  ]
}
```

> [!NOTE]
> Batch operations are transactional: if any single entry fails compilation or introduces an unresolved dependency, the entire batch is rejected and the current active dictionary remains unchanged.
