{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/FactionFile",
  "definitions": {
    "FactionFile": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "lore": {
          "type": "string"
        },
        "passive_positive": {
          "anyOf": [
            {
              "$ref": "#/definitions/AttrRef"
            },
            {
              "type": "null"
            }
          ]
        },
        "passive_negative": {
          "anyOf": [
            {
              "$ref": "#/definitions/AttrRef"
            },
            {
              "type": "null"
            }
          ]
        },
        "trait": {
          "anyOf": [
            {
              "$ref": "#/definitions/FactionTrait"
            },
            {
              "type": "null"
            }
          ]
        },
        "trait_title": {
          "type": "string"
        },
        "unit_templates": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Unit"
          }
        },
        "specialLists": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SpecialList"
          }
        },
        "accent": {
          "type": "string",
          "description": "Presentation: accent colour and icon id (no artwork)."
        },
        "icon": {
          "type": "string"
        },
        "meta": {
          "$ref": "#/definitions/FactionMeta"
        },
        "type": {
          "$ref": "#/definitions/DocType"
        },
        "str_version": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "str_version",
        "type",
        "unit_templates"
      ]
    },
    "AttrRef": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "value": {
          "type": [
            "number",
            "string"
          ]
        }
      },
      "required": [
        "id"
      ],
      "description": "A reference to a catalogue attribute (unit attribute, weapon attribute or weapon limitation) with its chosen parameter. `value` is a number for `param.kind === 'number'`, a weapon type for `'type'`, and a special-list name for `'list'`. Absent when the attribute has no parameter."
    },
    "FactionTrait": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "slots": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/TraitSlotValue"
          }
        },
        "name": {
          "type": "string",
          "description": "Display name chosen by the author."
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "id"
      ]
    },
    "TraitSlotValue": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "x": {
          "type": [
            "number",
            "string"
          ]
        },
        "slots": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/TraitSlotValue"
          }
        }
      }
    },
    "Unit": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "role": {
          "type": "string",
          "description": "Role label shown on the card, e.g. \"Leader\", \"Warrior\"."
        },
        "description": {
          "type": "string",
          "description": "Flavour text."
        },
        "lore": {
          "type": "string"
        },
        "skill": {
          "type": "number"
        },
        "defence": {
          "type": "number"
        },
        "armor": {
          "type": "boolean"
        },
        "unique": {
          "type": "boolean"
        },
        "outsider": {
          "type": "boolean"
        },
        "equipment": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Equipment"
          }
        },
        "attributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          }
        },
        "upgrades": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Upgrade"
          },
          "description": "Absent on spawned units, which may not have upgrades."
        },
        "selectedUpgrade": {
          "anyOf": [
            {
              "$ref": "#/definitions/Upgrade"
            },
            {
              "type": "null"
            }
          ]
        },
        "count": {
          "type": "number",
          "description": "Number of units in a force entry."
        },
        "loot": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LootRow"
          },
          "description": "Optional D6 loot table (RPG bestiary use)."
        },
        "specialLists": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SpecialList"
          },
          "description": "Special-action lists embedded on a standalone unit file."
        },
        "meta": {
          "$ref": "#/definitions/UnitMeta",
          "description": "Library shelf data (taxonomy.ts); read by the catalogue, never by the rules."
        }
      },
      "required": [
        "name",
        "skill",
        "defence",
        "armor",
        "equipment",
        "attributes"
      ],
      "description": "A single unit (skirmish) or a template for one. In a force it also carries `count` and `selectedUpgrade`. In a faction it is a template and its equipment lists every option a fielded unit may choose from."
    },
    "Equipment": {
      "anyOf": [
        {
          "$ref": "#/definitions/Weapon"
        },
        {
          "$ref": "#/definitions/Item"
        }
      ]
    },
    "Weapon": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/definitions/WeaponKind"
        },
        "name": {
          "type": "string"
        },
        "attacks": {
          "type": "number"
        },
        "range": {
          "type": "number"
        },
        "attributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          }
        },
        "limitations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          },
          "description": "At most one. Absent on weapons created by an effect."
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "attacks",
        "range",
        "attributes"
      ],
      "description": "Attack gear: anything with attacks and a range. Range 0 = melee."
    },
    "WeaponKind": {
      "type": "string",
      "enum": [
        "melee",
        "ranged"
      ]
    },
    "Item": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "item"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "grants": {
          "type": "object",
          "properties": {
            "attributes": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AttrRef"
              }
            },
            "body": {
              "type": "number",
              "description": "RPG-only stat modifiers; never affect points."
            },
            "agility": {
              "type": "number"
            },
            "mind": {
              "type": "number"
            },
            "spirit": {
              "type": "number"
            }
          },
          "required": [
            "attributes"
          ]
        }
      },
      "required": [
        "type",
        "name",
        "grants"
      ],
      "description": "Non-attack gear that grants a unit attribute. Never modifies Skill or Defence."
    },
    "Upgrade": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "effects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Effect"
          }
        },
        "condition": {
          "anyOf": [
            {
              "$ref": "#/definitions/ConditionRef"
            },
            {
              "type": "null"
            }
          ]
        },
        "aoe": {
          "anyOf": [
            {
              "$ref": "#/definitions/AreaOfEffect"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "name",
        "effects"
      ],
      "description": "A purchasable special action for a unit. Priced from its blocks; a stored `cost` is never trusted and is removed on import."
    },
    "Effect": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "x": {
          "type": "number",
          "description": "Numeric parameter, bounded by the catalogue entry's min/max."
        },
        "option": {
          "type": "string",
          "description": "Chosen option key for option-varying effects."
        },
        "attrId": {
          "type": "string",
          "description": "Gain / grant attribute: which attribute, its value, and (gain only) the target."
        },
        "attrValue": {
          "type": [
            "number",
            "string",
            "null"
          ]
        },
        "attrTarget": {
          "type": "string"
        },
        "width": {
          "type": "number",
          "description": "create_obstacle"
        },
        "height": {
          "type": "number"
        },
        "spawnedUnit": {
          "$ref": "#/definitions/Unit",
          "description": "create_new_unit"
        },
        "weapon": {
          "$ref": "#/definitions/Weapon",
          "description": "create_attack"
        },
        "noLos": {
          "type": "boolean"
        }
      },
      "required": [
        "id"
      ],
      "description": "One building block of an upgrade or special action. Which of the optional fields apply depends on the catalogue entry `id` points to."
    },
    "ConditionRef": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "x": {
          "type": "number"
        }
      },
      "required": [
        "id"
      ]
    },
    "AreaOfEffect": {
      "type": "object",
      "properties": {
        "x": {
          "type": "number",
          "description": "Radius in inches, 1–12."
        },
        "allFactions": {
          "type": "boolean",
          "description": "Hits friend and foe alike (discounted)."
        }
      },
      "required": [
        "x"
      ]
    },
    "LootRow": {
      "type": "object",
      "properties": {
        "roll": {
          "type": "number",
          "description": "D6 result 1–6."
        },
        "text": {
          "type": "string"
        }
      },
      "required": [
        "roll",
        "text"
      ],
      "description": "One row of a unit's D6 loot table."
    },
    "SpecialList": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SpecialAction"
          }
        },
        "meta": {
          "$ref": "#/definitions/SpecialListMeta"
        }
      },
      "required": [
        "name",
        "actions"
      ]
    },
    "SpecialAction": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "effects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Effect"
          }
        },
        "aoe": {
          "anyOf": [
            {
              "$ref": "#/definitions/AreaOfEffect"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "name",
        "effects"
      ],
      "description": "A special action inside a special-action list: same blocks, no condition."
    },
    "SpecialListMeta": {
      "type": "object",
      "properties": {
        "setting": {
          "$ref": "#/definitions/Setting"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "creator": {
          "type": "string"
        },
        "date": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        },
        "category": {
          "$ref": "#/definitions/SpecialCategory"
        }
      }
    },
    "Setting": {
      "type": "string",
      "enum": [
        "fantasy",
        "sci-fi",
        "any"
      ]
    },
    "SpecialCategory": {
      "type": "string",
      "enum": [
        "elemental",
        "divine",
        "nature",
        "dark",
        "arcane",
        "mind",
        "tech",
        "martial",
        "trickery",
        "command"
      ]
    },
    "UnitMeta": {
      "type": "object",
      "properties": {
        "setting": {
          "$ref": "#/definitions/Setting"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "creator": {
          "type": "string"
        },
        "date": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        },
        "category": {
          "$ref": "#/definitions/UnitCategory"
        },
        "threat": {
          "$ref": "#/definitions/Threat",
          "description": "The author's intent; the audit proves the fielded maximum lands in the band."
        },
        "family": {
          "type": "string",
          "description": "Variants of one creature (Wolf → Dire Wolf → Winter Wolf) share a family and climb the bands together."
        }
      },
      "description": "A unit's shelf: what kind of creature, which threat band its price must land in, and its variant family."
    },
    "UnitCategory": {
      "type": "string",
      "enum": [
        "beast",
        "humanoid",
        "giant",
        "undead",
        "construct",
        "spirit",
        "fiend",
        "dragon",
        "aberration",
        "plant",
        "alien",
        "swarm"
      ]
    },
    "Threat": {
      "type": "string",
      "enum": [
        "low",
        "moderate",
        "high",
        "severe",
        "extreme",
        "legendary"
      ]
    },
    "FactionMeta": {
      "type": "object",
      "properties": {
        "setting": {
          "$ref": "#/definitions/Setting"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "creator": {
          "type": "string"
        },
        "date": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        },
        "playsLike": {
          "type": "string",
          "description": "\"Power-armoured space knights: battle-brothers, jump troops, heavy plate and walkers.\""
        }
      },
      "description": "A faction's shelf: the kinds of army it stands in for, in generic words."
    },
    "DocType": {
      "type": "string",
      "enum": [
        "unit",
        "faction",
        "force",
        "special_actions",
        "pgcharacter",
        "adventure",
        "world"
      ]
    }
  },
  "$id": "https://simple-tabletop.example/schema/faction.schema.json",
  "title": "Simple Tabletop FactionFile"
}
