{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.local/knowledge-graph.schema.json",
  "title": "Dual-View Knowledge Graph Schema",
  "description": "Schema for generated graph payload with book hierarchy view and knowledge relation view.",
  "type": "object",
  "required": ["meta", "views"],
  "properties": {
    "meta": {
      "type": "object",
      "required": ["title", "version", "updatedAt", "description"],
      "properties": {
        "title": { "type": "string" },
        "version": { "type": "string" },
        "updatedAt": { "type": "string", "format": "date" },
        "description": { "type": "string" },
        "language": { "type": "string" },
        "owner": { "type": "string" }
      },
      "additionalProperties": true
    },
    "sourceRef": {
      "type": "object",
      "properties": {
        "file": { "type": "string" },
        "relationTypeFile": { "type": "string" }
      },
      "additionalProperties": true
    },
    "relationTypes": {
      "type": "object",
      "additionalProperties": true
    },
    "stats": {
      "type": "object",
      "additionalProperties": true
    },
    "views": {
      "type": "object",
      "required": ["book", "knowledge"],
      "properties": {
        "book": { "$ref": "#/$defs/view" },
        "knowledge": { "$ref": "#/$defs/view" }
      }
    }
  },
  "$defs": {
    "view": {
      "type": "object",
      "required": ["nodes", "edges"],
      "properties": {
        "nodes": {
          "type": "array",
          "items": { "$ref": "#/$defs/node" }
        },
        "edges": {
          "type": "array",
          "items": { "$ref": "#/$defs/edge" }
        }
      }
    },
    "node": {
      "type": "object",
      "required": ["id", "title", "type"],
      "properties": {
        "id": { "type": "string" },
        "rawId": { "type": "string" },
        "title": { "type": "string" },
        "titleI18n": { "$ref": "#/$defs/i18nText" },
        "type": {
          "type": "string",
          "enum": [
            "book",
            "chapter",
            "section",
            "knowledge",
            "concept",
            "method",
            "law",
            "theory",
            "algorithm",
            "model"
          ]
        },
        "summary": { "type": "string" },
        "summaryI18n": { "$ref": "#/$defs/i18nText" },
        "discipline": { "type": "string" },
        "knowledgeType": { "type": "string" },
        "difficulty": {
          "type": "string",
          "enum": ["beginner", "intermediate", "advanced"]
        },
        "tags": {
          "type": "array",
          "items": { "type": "string" }
        },
        "aliases": {
          "type": "array",
          "items": { "type": "string" }
        },
        "provenanceLinks": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["type", "bookTitle", "chapter", "section"],
            "properties": {
              "type": { "type": "string", "enum": ["defined_in", "cite_from", "support"] },
              "bookId": { "type": "string" },
              "bookTitle": { "type": "string" },
              "bookTitleI18n": { "$ref": "#/$defs/i18nText" },
              "chapter": { "type": "string" },
              "chapterI18n": { "$ref": "#/$defs/i18nText" },
              "section": { "type": "string" },
              "sectionI18n": { "$ref": "#/$defs/i18nText" },
              "link": { "type": "string" }
            }
          }
        },
        "bookId": { "type": "string" },
        "bookTitle": { "type": "string" },
        "chapterId": { "type": "string" },
        "chapterTitle": { "type": "string" },
        "sectionId": { "type": "string" },
        "sectionTitle": { "type": "string" }
      },
      "additionalProperties": true
    },
    "edge": {
      "type": "object",
      "required": ["source", "target", "type", "reason"],
      "properties": {
        "source": { "type": "string" },
        "target": { "type": "string" },
        "type": { "type": "string" },
        "reason": { "type": "string" },
        "reasonI18n": { "$ref": "#/$defs/i18nText" },
        "domain": { "type": "string" },
        "weight": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "additionalProperties": true
    },
    "i18nText": {
      "type": "object",
      "required": ["zh", "en"],
      "properties": {
        "zh": { "type": "string" },
        "en": { "type": "string" }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
