{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://assets.tiantianspeak.com/schemas/collection-set.schema.json",
  "title": "Collection set（题库 / 内容集合）",
  "description": "一个文件 = 一个 collection：一组内容，每个 item 是一篇文章。item 可以直接写正文，也可以用 `{\"article\": \"x.article.json\"}` 引用 collection article 文件。也接受更宽松的简写：字符串数组、`[{title,text}]` 数组（见文档）。",
  "type": "object",
  "required": [
    "items"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^(?!\\.)[^\\s/\\\\]{1,64}$",
      "maxLength": 64,
      "description": "题库 id，如 `hsk-1`。写了它「读过没有」按 `bank:<id>/<条目id>` 记，重新下载后保持；同 id 再次下载内容不同会覆盖。"
    },
    "name": {
      "type": "string",
      "description": "名称；不写时用文件名。"
    },
    "description": {
      "type": "string",
      "description": "简介（也认 `简介` / `说明`）。"
    },
    "category": {
      "type": "string",
      "description": "一级分类，用于筛选（也认 `分类`）。分级标签请用 `tags`。"
    },
    "language": {
      "enum": [
        "zh",
        "en"
      ],
      "description": "文本语言。读取时也宽容 `en-US` / `english` / `英文` 等；发布的文件请写 `zh` 或 `en`。"
    },
    "tags": {
      "description": "分级标签。字符串数组（也可写成单个字符串）；每个标签是一条层级路径。",
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[^/\\s][^/]*(/[^/]+)*$",
            "description": "分级标签：用 `/` 分隔的层级路径，如 `HSK/初级`、`名著/外国文学`。"
          },
          "uniqueItems": true
        },
        {
          "type": "string",
          "minLength": 1,
          "pattern": "^[^/\\s][^/]*(/[^/]+)*$",
          "description": "分级标签：用 `/` 分隔的层级路径，如 `HSK/初级`、`名著/外国文学`。"
        }
      ]
    },
    "items": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/inlineItem"
          },
          {
            "$ref": "#/$defs/articleRef"
          }
        ]
      }
    }
  },
  "$defs": {
    "inlineItem": {
      "title": "直接写正文的 item",
      "type": "object",
      "required": [
        "text"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^(?!\\.)[^\\s/\\\\]{1,64}$",
          "maxLength": 64,
          "description": "稳定标识：字母、数字、汉字和 `._-`，≤64 字符，不以 `.` 开头；不合格的值读取时当作没写。"
        },
        "hash": {
          "type": "string",
          "pattern": "^(?!\\.)[^\\s/\\\\]{1,64}$",
          "maxLength": 64,
          "description": "稳定标识：字母、数字、汉字和 `._-`，≤64 字符，不以 `.` 开头；不合格的值读取时当作没写。"
        },
        "title": {
          "type": "string",
          "description": "标题；不写取正文第一行（最多 24 字）。"
        },
        "text": {
          "type": "string",
          "minLength": 1,
          "description": "正文。"
        },
        "audio": {
          "type": "string",
          "pattern": "^https?://",
          "description": "示范音频，http(s) 网址（mp3 / m4a / m3u8）。"
        },
        "pinyin": {
          "type": "string",
          "description": "每个汉字一个带调拼音，空格分隔，与 `text` 里的汉字一一对应；个数对不上时读取时整段拼音被忽略。"
        },
        "translation": {
          "type": "string",
          "description": "译文。"
        },
        "align": {
          "enum": [
            "center",
            "left"
          ],
          "description": "`center` 居中（适合诗词）；不写 = 左对齐。读取时也认 `居中`。"
        }
      },
      "additionalProperties": true,
      "description": "其他字段（如 `level`、`slug`）会被忽略，可以放自己的备注。"
    },
    "articleRef": {
      "title": "引用 article 文件的 item",
      "type": "object",
      "required": [
        "article"
      ],
      "properties": {
        "article": {
          "type": "string",
          "pattern": "^(?!/)(?!.*://)(?!.*(^|/)\\.\\.(/|$)).+\\.json$",
          "description": "article 文件路径，相对本 collection 文件所在目录，以 `.json` 结尾，建议 `*.article.json`。"
        },
        "id": {
          "type": "string",
          "pattern": "^(?!\\.)[^\\s/\\\\]{1,64}$",
          "maxLength": 64,
          "description": "稳定标识：字母、数字、汉字和 `._-`，≤64 字符，不以 `.` 开头；不合格的值读取时当作没写。"
        },
        "hash": {
          "type": "string",
          "pattern": "^(?!\\.)[^\\s/\\\\]{1,64}$",
          "maxLength": 64,
          "description": "稳定标识：字母、数字、汉字和 `._-`，≤64 字符，不以 `.` 开头；不合格的值读取时当作没写。"
        },
        "title": {
          "type": "string",
          "description": "覆盖 article 自己的名称（可选）。"
        }
      },
      "not": {
        "anyOf": [
          {
            "required": [
              "text"
            ]
          },
          {
            "required": [
              "content"
            ]
          },
          {
            "required": [
              "passage"
            ]
          },
          {
            "required": [
              "body"
            ]
          },
          {
            "required": [
              "question"
            ]
          },
          {
            "required": [
              "prompt"
            ]
          }
        ]
      },
      "additionalProperties": true,
      "description": "item 里的 `article` 是以 `.json` 结尾的字符串、且没有别的正文字段时，就是引用；否则 `article` 仍按旧写法当作正文字段。"
    }
  },
  "examples": [
    {
      "id": "gulliver",
      "name": "格列佛游记 · 小人国",
      "tags": [
        "名著/外国文学"
      ],
      "items": [
        {
          "title": "海上遇险",
          "text": "……"
        },
        {
          "article": "articles/lilliput-01.article.json"
        }
      ]
    }
  ]
}
