{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Terminal Realms Adventure Package",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "adventure", "commandSet", "playerTemplates", "items", "characters", "rooms"],
  "properties": {
    "schemaVersion": { "type": "string" },
    "adventure": { "$ref": "#/$defs/adventure" },
    "commandSet": { "type": "array", "items": { "$ref": "#/$defs/command" } },
    "playerTemplates": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/player" } },
    "items": { "type": "array", "items": { "$ref": "#/$defs/item" } },
    "characters": { "type": "array", "items": { "$ref": "#/$defs/character" } },
    "rooms": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/room" } }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
    "idList": { "type": "array", "items": { "$ref": "#/$defs/id" }, "uniqueItems": true },
    "adventure": {
      "type": "object",
      "required": ["id", "title", "version", "startRoom", "intro"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "title": { "type": "string", "minLength": 1 },
        "subtitle": { "type": "string" },
        "author": { "type": "string" },
        "version": { "type": "string" },
        "startRoom": { "$ref": "#/$defs/id" },
        "intro": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "command": {
      "type": "object",
      "required": ["code", "syntax", "description"],
      "properties": {
        "code": { "type": "string" },
        "syntax": { "type": "string" },
        "description": { "type": "string" }
      },
      "additionalProperties": false
    },
    "player": {
      "type": "object",
      "required": ["id", "name", "class", "level", "description", "hp", "stats", "inventory", "equipment"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "name": { "type": "string" },
        "class": { "type": "string" },
        "level": { "type": "integer", "minimum": 1 },
        "description": { "type": "string" },
        "hp": {
          "type": "object",
          "required": ["current", "max"],
          "properties": {
            "current": { "type": "integer", "minimum": 0 },
            "max": { "type": "integer", "minimum": 1 }
          }
        },
        "stats": { "type": "object", "additionalProperties": { "type": "integer" } },
        "inventory": { "$ref": "#/$defs/idList" },
        "equipment": {
          "type": "object",
          "additionalProperties": { "oneOf": [{ "$ref": "#/$defs/id" }, { "type": "null" }] }
        }
      },
      "additionalProperties": false
    },
    "item": {
      "type": "object",
      "required": ["id", "name", "aliases", "description", "closer", "portable", "slot"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "name": { "type": "string" },
        "aliases": { "type": "array", "items": { "type": "string" } },
        "description": { "type": "string" },
        "closer": { "type": "string" },
        "portable": { "type": "boolean" },
        "slot": { "oneOf": [{ "type": "string" }, { "type": "null" }] },
        "effect": {
          "type": "object",
          "required": ["type", "amount", "consume"],
          "properties": {
            "type": { "type": "string" },
            "amount": { "type": "integer" },
            "consume": { "type": "boolean" }
          }
        }
      },
      "additionalProperties": false
    },
    "character": {
      "type": "object",
      "required": ["id", "name", "aliases", "type", "description", "closer", "dialogue"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "name": { "type": "string" },
        "aliases": { "type": "array", "items": { "type": "string" } },
        "type": { "enum": ["npc", "enemy"] },
        "description": { "type": "string" },
        "closer": { "type": "string" },
        "dialogue": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "exit": {
      "type": "object",
      "required": ["label", "to", "status", "description"],
      "properties": {
        "label": { "type": "string" },
        "to": { "oneOf": [{ "$ref": "#/$defs/id" }, { "type": "null" }] },
        "status": { "enum": ["open", "closed", "locked", "blocked"] },
        "key": { "$ref": "#/$defs/id" },
        "description": { "type": "string" },
        "blockedText": { "type": "string" },
        "lockedText": { "type": "string" },
        "edgeText": { "type": "string" }
      },
      "additionalProperties": false
    },
    "room": {
      "type": "object",
      "required": ["id", "name", "code", "description", "closer", "ambient", "items", "characters", "exits"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "name": { "type": "string" },
        "code": { "type": "string" },
        "description": { "type": "string" },
        "closer": { "type": "string" },
        "ambient": { "type": "array", "items": { "type": "string" } },
        "items": { "$ref": "#/$defs/idList" },
        "characters": { "$ref": "#/$defs/idList" },
        "exits": {
          "type": "object",
          "required": ["north", "south", "east", "west"],
          "properties": {
            "north": { "$ref": "#/$defs/exit" },
            "south": { "$ref": "#/$defs/exit" },
            "east": { "$ref": "#/$defs/exit" },
            "west": { "$ref": "#/$defs/exit" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  }
}
