{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cheeleong.dev/wwn-system-json/systems/table.schema.json",
  "title": "WWN Table",
  "type": "object",
  "allOf": [{ "$ref": "https://cheeleong.dev/wwn-system-json/systems/common.schema.json#/$defs/Entity" }],
  "$defs": {
    "Cell": {
      "oneOf": [
        { "type": ["string", "number", "boolean"] },
        { "$ref": "https://cheeleong.dev/wwn-system-json/systems/common.schema.json#/$defs/NodeReference" },
        { "$ref": "https://cheeleong.dev/wwn-system-json/systems/common.schema.json#/$defs/DiceExpression" }
      ]
    },
    "Row": {
      "type": "object",
      "properties": {
        "position": { "type": "integer", "minimum": 1 },
        "range": { "type": "string", "minLength": 1 },
        "result": { "$ref": "#/$defs/Cell" },
        "cells": { "type": "array", "items": { "$ref": "#/$defs/Cell" }, "minItems": 1 }
      },
      "required": ["position", "cells"],
      "anyOf": [{ "required": ["range"] }, { "required": ["result"] }],
      "unevaluatedProperties": false
    }
  },
  "properties": {
    "@type": { "const": "Table" },
    "tableType": { "type": "string", "minLength": 1 },
    "diceExpression": { "type": "string" },
    "columns": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
    "rows": { "type": "array", "items": { "$ref": "#/$defs/Row" }, "minItems": 1 },
    "notes": { "type": "array", "items": { "type": "string" } },
    "relatedRules": { "type": "array", "items": { "$ref": "https://cheeleong.dev/wwn-system-json/systems/common.schema.json#/$defs/NodeReference" }, "uniqueItems": true }
  },
  "required": ["tableType", "rows", "source"],
  "unevaluatedProperties": false
}
