{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://codexcryptica.com/schemas/adventure-json/v1.json",
  "title": "Codex Cryptica Adventure JSON v1",
  "description": "Public versioned interchange contract for source-derived tabletop RPG adventures without playthrough state.",
  "type": "object",
  "properties": {
    "formatVersion": {
      "type": "string",
      "const": "adventure-json/v1"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_-]{3,64}$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
    },
    "description": {
      "type": "string"
    },
    "premise": {
      "type": "object",
      "properties": {
        "background": {
          "type": "string"
        },
        "hook": {
          "type": "string"
        },
        "theme": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tone": {
          "type": "string"
        }
      },
      "required": ["background", "hook"],
      "additionalProperties": false
    },
    "source": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1
        },
        "authors": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "publisher": {
          "type": "string"
        },
        "publishedDate": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "license": {
          "type": "string"
        },
        "documentHash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": ["title"],
      "additionalProperties": false
    },
    "system": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "targetParty": {
          "type": "object",
          "properties": {
            "sizeMin": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "sizeMax": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "levelMin": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "levelMax": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "additionalProperties": false
        }
      },
      "required": ["name"],
      "additionalProperties": false
    },
    "locations": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "summary": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "parentLocationId": {
            "type": "string",
            "minLength": 1
          },
          "connections": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "targetLocationId": {
                  "type": "string",
                  "minLength": 1
                },
                "description": {
                  "type": "string"
                },
                "travelConditions": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": ["targetLocationId"],
              "additionalProperties": false
            }
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "name", "summary", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "actors": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "summary": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "motivation": {
            "type": "string"
          },
          "disposition": {
            "type": "string"
          },
          "factionId": {
            "type": "string",
            "minLength": 1
          },
          "locationId": {
            "type": "string",
            "minLength": 1
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "name", "summary", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "factions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "summary": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "goals": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "dispositionTowardsParty": {
            "type": "string"
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "name", "summary", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "scenes": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "summary": {
            "type": "string"
          },
          "locationId": {
            "type": "string",
            "minLength": 1
          },
          "readAloud": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "body": {
            "type": "string"
          },
          "conditions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "branches": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "targetSceneId": {
                  "type": "string",
                  "minLength": 1
                },
                "description": {
                  "type": "string",
                  "minLength": 1
                },
                "condition": {
                  "type": "string"
                },
                "optional": {
                  "type": "boolean"
                }
              },
              "required": ["targetSceneId", "description"],
              "additionalProperties": false
            }
          },
          "optional": {
            "type": "boolean"
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "title", "summary", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "encounters": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "sceneId": {
            "type": "string",
            "minLength": 1
          },
          "locationId": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": "string"
          },
          "conditions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "actorIds": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "alternativeSolutions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "method": {
                  "type": "string",
                  "minLength": 1
                },
                "description": {
                  "type": "string",
                  "minLength": 1
                },
                "socialBypassOfCombat": {
                  "type": "boolean"
                }
              },
              "required": ["method", "description"],
              "additionalProperties": false
            }
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "description",
          "alternativeSolutions",
          "visibility",
          "epistemicStatus"
        ],
        "additionalProperties": false
      }
    },
    "clues": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string",
            "minLength": 1
          },
          "reveals": {
            "type": "string"
          },
          "leadTargetId": {
            "type": "string",
            "minLength": 1
          },
          "placedLocationId": {
            "type": "string",
            "minLength": 1
          },
          "placedActorId": {
            "type": "string",
            "minLength": 1
          },
          "placedSceneId": {
            "type": "string",
            "minLength": 1
          },
          "alternativeSourceId": {
            "type": "string",
            "minLength": 1
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "text", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "rumours": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string",
            "minLength": 1
          },
          "truth": {
            "type": "string",
            "enum": ["true", "false", "partially-true", "unverified"]
          },
          "sourceActorId": {
            "type": "string",
            "minLength": 1
          },
          "sourceLocationId": {
            "type": "string",
            "minLength": 1
          },
          "targetEntityId": {
            "type": "string",
            "minLength": 1
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "text", "truth", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "summary": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "locationId": {
            "type": "string",
            "minLength": 1
          },
          "actorId": {
            "type": "string",
            "minLength": 1
          },
          "visibility": {
            "type": "string",
            "enum": ["player-visible", "gm-only"]
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "name", "summary", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "secrets": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string",
            "minLength": 1
          },
          "relatedEntityIds": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "visibility": {
            "type": "string",
            "const": "gm-only"
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "text", "visibility", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "endings": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "conditions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["explicit", "inferred", "ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "description", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "unresolved": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "code": {
            "type": "string",
            "minLength": 1
          },
          "message": {
            "type": "string",
            "minLength": 1
          },
          "relatedEntityId": {
            "type": "string",
            "minLength": 1
          },
          "context": {
            "type": "string"
          },
          "epistemicStatus": {
            "type": "string",
            "enum": ["ambiguous", "unresolved"]
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "pageEnd": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "chapter": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "minLength": 1
              },
              "anchor": {
                "type": "string",
                "minLength": 1
              },
              "textQuote": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["id", "code", "message", "epistemicStatus"],
        "additionalProperties": false
      }
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^(?:[a-zA-Z0-9_-]+\\.)+[a-zA-Z0-9_-]+$"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema0"
      }
    }
  },
  "required": [
    "formatVersion",
    "id",
    "title",
    "version",
    "premise",
    "source",
    "locations",
    "actors",
    "factions",
    "scenes",
    "encounters",
    "clues",
    "rumours",
    "items",
    "secrets",
    "endings",
    "unresolved"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    }
  }
}
