{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://assets.tiantianspeak.com/schemas/collection-package.schema.json",
  "title": "Collection package（题库包）",
  "description": "把多个 collection 组织成一棵有序的树。文件名建议 `*.package.json`；任何含 `children` 且没有 `items` 的对象都会被当作题库包。叶子用相对路径引用 collection（set 或 article）文件，分组可嵌套，`children` 数组顺序就是显示顺序。",
  "type": "object",
  "required": [
    "children"
  ],
  "properties": {
    "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/初级`、`名著/外国文学`。"
        }
      ]
    },
    "children": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/group"
          },
          {
            "$ref": "#/$defs/leaf"
          }
        ]
      }
    }
  },
  "not": {
    "required": [
      "items"
    ]
  },
  "$defs": {
    "group": {
      "title": "分组",
      "type": "object",
      "required": [
        "name",
        "children"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "children": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "$ref": "#/$defs/group"
              },
              {
                "$ref": "#/$defs/leaf"
              }
            ]
          }
        }
      },
      "additionalProperties": false
    },
    "leaf": {
      "title": "叶子（引用 collection）",
      "type": "object",
      "required": [
        "collection"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "显示名；省略时显示 collection 自己的名称。"
        },
        "collection": {
          "type": "string",
          "pattern": "^(?!/)(?!.*://)(?!.*(^|/)\\.\\.(/|$)).+\\.json$",
          "description": "collection 文件路径，相对包文件所在目录，可带子目录。"
        }
      },
      "additionalProperties": false
    }
  },
  "examples": [
    {
      "name": "中小学生示范朗读",
      "tags": [
        "语文教材"
      ],
      "children": [
        {
          "name": "小学",
          "children": [
            {
              "name": "一年级",
              "collection": "中小学生示范朗读/一年级.json"
            }
          ]
        }
      ]
    }
  ]
}
