{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sashite.dev/schemas/pon/1.0.0/schema.json",
  "title": "PON v1.0.0",
  "description": "Position Object Notation (PON) v1.0.0 - JSON-based position encoding format for abstract strategy board games",
  "type": "object",
  "required": ["board", "hands", "styles", "turn"],
  "additionalProperties": false,
  "properties": {
    "board": {
      "$ref": "#/$defs/board"
    },
    "hands": {
      "$ref": "#/$defs/hands"
    },
    "styles": {
      "$ref": "#/$defs/styles"
    },
    "turn": {
      "$ref": "#/$defs/turn"
    }
  },
  "$defs": {
    "board": {
      "title": "Board",
      "description": "Multi-dimensional array representing board structure and occupancy. Nesting depth determines dimensionality.",
      "oneOf": [
        {
          "$ref": "#/$defs/board1D"
        },
        {
          "$ref": "#/$defs/boardND"
        }
      ]
    },
    "board1D": {
      "title": "1D Board",
      "description": "One-dimensional board: a single array of squares",
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/square"
      }
    },
    "boardND": {
      "title": "N-Dimensional Board (N ≥ 2)",
      "description": "Multi-dimensional board: nested arrays where innermost arrays are ranks",
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/board1D"
          },
          {
            "$ref": "#/$defs/boardND"
          }
        ]
      }
    },
    "square": {
      "title": "Square",
      "description": "A single square on the board: null for empty, or an EPIN token for a piece",
      "oneOf": [
        {
          "type": "null",
          "description": "Empty square"
        },
        {
          "$ref": "#/$defs/epinToken"
        }
      ]
    },
    "epinToken": {
      "title": "EPIN Token",
      "description": "Extended Piece Identifier Notation token: [state-modifier]<letter>[terminal-marker][derivation-marker]",
      "type": "string",
      "pattern": "^[+-]?[A-Za-z]\\^?'?$"
    },
    "hands": {
      "title": "Hands",
      "description": "Pieces held in each player's hand",
      "type": "object",
      "required": ["first", "second"],
      "additionalProperties": false,
      "properties": {
        "first": {
          "$ref": "#/$defs/hand",
          "description": "Pieces in the First Player's hand"
        },
        "second": {
          "$ref": "#/$defs/hand",
          "description": "Pieces in the Second Player's hand"
        }
      }
    },
    "hand": {
      "title": "Hand",
      "description": "Array of EPIN tokens representing pieces in a player's hand",
      "type": "array",
      "items": {
        "$ref": "#/$defs/epinToken"
      }
    },
    "styles": {
      "title": "Styles",
      "description": "Player Style for each Player Side, encoded as SIN tokens",
      "type": "object",
      "required": ["first", "second"],
      "additionalProperties": false,
      "properties": {
        "first": {
          "$ref": "#/$defs/sinTokenUppercase",
          "description": "First Player's Style (must be uppercase)"
        },
        "second": {
          "$ref": "#/$defs/sinTokenLowercase",
          "description": "Second Player's Style (must be lowercase)"
        }
      }
    },
    "sinTokenUppercase": {
      "title": "SIN Token (Uppercase)",
      "description": "Style Identifier Notation token for First Player: single uppercase ASCII letter",
      "type": "string",
      "pattern": "^[A-Z]$"
    },
    "sinTokenLowercase": {
      "title": "SIN Token (Lowercase)",
      "description": "Style Identifier Notation token for Second Player: single lowercase ASCII letter",
      "type": "string",
      "pattern": "^[a-z]$"
    },
    "turn": {
      "title": "Turn",
      "description": "The Active Player's Side",
      "type": "string",
      "enum": ["first", "second"]
    }
  }
}
