{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:suishenjing:scripture:1",
  "title": "随身经经文交换格式 v1",
  "description": "结构校验。段落唯一性、原文匹配、总段数、更新兼容性等语义约束由 App 与同源命令行校验器检查。",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "schemaVersion",
    "book"
  ],
  "properties": {
    "format": {
      "const": "suishenjing.scripture"
    },
    "schemaVersion": {
      "const": 1
    },
    "book": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "revision",
        "title",
        "fullTitle",
        "author",
        "tradition",
        "introduction",
        "tags",
        "aliases",
        "source",
        "chapters"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_-]{0,63}$"
        },
        "revision": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2147483647
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "fullTitle": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "author": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "tradition": {
          "enum": [
            "buddhist",
            "taoist"
          ]
        },
        "introduction": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4000
        },
        "tags": {
          "type": "array",
          "items": {
            "enum": [
              "common",
              "prajna",
              "pureLand",
              "dizang",
              "mahayana",
              "chan",
              "precepts",
              "mantra",
              "study",
              "cultivation",
              "ritual",
              "ethics"
            ]
          },
          "minItems": 0,
          "maxItems": 12,
          "uniqueItems": true
        },
        "aliases": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "minItems": 0,
          "maxItems": 30
        },
        "source": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "name",
            "version",
            "url",
            "license",
            "licenseURL",
            "notes"
          ],
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "url": {
              "type": "string",
              "anyOf": [
                {
                  "const": ""
                },
                {
                  "pattern": "^https?://[^/\\s]+[^\\s]*$"
                }
              ]
            },
            "license": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            },
            "licenseURL": {
              "type": "string",
              "anyOf": [
                {
                  "const": ""
                },
                {
                  "pattern": "^https?://[^/\\s]+[^\\s]*$"
                }
              ]
            },
            "notes": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4000
            }
          }
        },
        "chapters": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "title",
              "paragraphs"
            ],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]{0,63}$"
              },
              "title": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "paragraphs": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "id",
                    "text",
                    "kind",
                    "sourceLocator",
                    "terms"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_-]{0,63}$"
                    },
                    "text": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 20000
                    },
                    "kind": {
                      "enum": [
                        "prose",
                        "verse",
                        "mantra"
                      ]
                    },
                    "sourceLocator": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 300
                    },
                    "annotation": {
                      "anyOf": [
                        {
                          "type": "object",
                          "additionalProperties": false,
                          "required": [
                            "text",
                            "attribution"
                          ],
                          "properties": {
                            "text": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 10000
                            },
                            "attribution": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 1000
                            }
                          }
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "terms": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "word",
                          "pinyin",
                          "meaning",
                          "attribution",
                          "automatic"
                        ],
                        "properties": {
                          "word": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 30
                          },
                          "pinyin": {
                            "type": "string",
                            "minLength": 0,
                            "maxLength": 200
                          },
                          "meaning": {
                            "type": "string",
                            "minLength": 0,
                            "maxLength": 4000
                          },
                          "attribution": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 1000
                          },
                          "automatic": {
                            "type": "boolean"
                          }
                        }
                      },
                      "minItems": 0,
                      "maxItems": 100
                    }
                  }
                },
                "minItems": 1,
                "maxItems": 30000
              }
            }
          },
          "minItems": 1,
          "maxItems": 500
        }
      }
    }
  }
}
