{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://fupan-ge-wiki.pages.dev/spec/schema/instance-schema.json",
  "title": "InvestmentOntologyKB",
  "description": "投资知识本体 — 实例数据层 JSON Schema v2.0。定义知识条目/题材/个股/交易日/案例等实例的字段结构，用于自动校验知识库数据合法性。与 organization-schema.json（规范层）配合使用。",
  "type": "object",
  "required": ["meta", "classes", "relations", "instances"],
  "additionalProperties": false,
  "properties": {
    "meta": {
      "type": "object",
      "required": ["name", "version", "schemaVersion", "lastUpdated"],
      "additionalProperties": false,
      "properties": {
        "name": {"const": "InvestmentOntologyKB"},
        "version": {"type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$", "description": "实例数据版本，如 1.0.0"},
        "schemaVersion": {"const": "2.0.0", "description": "本 schema 版本，跟随规范层版本号"},
        "created": {"type": "string", "format": "date"},
        "lastUpdated": {"type": "string", "format": "date"},
        "source": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "repo": {"type": "string", "description": "数据仓库地址"},
            "spec": {"type": "string", "description": "规范层文件路径", "default": "wiki/overview/schema/organization-schema.json"}
          }
        }
      }
    },

    "classes": {
      "type": "object",
      "description": "类定义（TBox 轻量声明）。实例必须挂在此处列出的类下。",
      "additionalProperties": {
        "type": "object",
        "required": ["label", "domain"],
        "additionalProperties": false,
        "properties": {
          "label": {"type": "string"},
          "description": {"type": "string"},
          "domain": {
            "type": "string",
            "enum": ["D1_methodology", "D2_sector", "D3_live", "meta"],
            "description": "所属域，对齐 organization-schema 的三域模型"
          },
          "parentClass": {"type": "string"}
        }
      }
    },

    "relations": {
      "type": "array",
      "description": "关系类型声明。每条关系定义两端类与基数。",
      "items": {
        "type": "object",
        "required": ["id", "name", "fromClass", "toClass", "cardinality"],
        "additionalProperties": false,
        "properties": {
          "id": {"type": "string", "pattern": "^R\\d{3}$"},
          "name": {"type": "string"},
          "fromClass": {"type": "string"},
          "toClass": {"type": "string"},
          "cardinality": {"type": "string", "enum": ["1:1", "1:N", "N:M"]},
          "inverse": {"type": "string"},
          "pageLink": {
            "type": "boolean",
            "default": true,
            "description": "该关系是否在 wiki 页面中生成双向链接。共现类关系必须为 false，避免图谱噪声。"
          }
        }
      }
    },

    "instances": {
      "type": "object",
      "required": ["Person", "Knowledge", "Theme", "Stock", "TradingDay", "KnowledgeCase"],
      "additionalProperties": false,
      "properties": {

        "Person": {
          "type": "array",
          "description": "投顾/老师/作者实体。",
          "items": {
            "type": "object",
            "required": ["id", "name"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^P\\d+$"},
              "name": {"type": "string"},
              "alias": {"type": "array", "items": {"type": "string"}, "description": "别名/称呼，如 李朋/皆明/争气"},
              "role": {
                "type": "string",
                "enum": ["首席投顾", "投顾", "助理", "其他"]
              }
            }
          }
        },

        "Knowledge": {
          "type": "array",
          "description": "方法论知识点（对应 wiki/concept/、comparisons/、心法综论）。",
          "items": {
            "type": "object",
            "required": ["id", "name", "category", "difficulty", "description", "content", "rules", "authorId"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^K\\d{3}$"},
              "name": {"type": "string", "maxLength": 20},
              "category": {
                "type": "string",
                "enum": ["交易模式", "大势分析方法", "账户管理", "情绪周期", "节点判断", "心法原则", "模式对比"],
                "description": "对应 organization-schema.controlledVocabulary"
              },
              "subcategory": {"type": "string"},
              "difficulty": {"type": "string", "enum": ["入门", "进阶", "高级"]},
              "description": {"type": "string", "maxLength": 120},
              "content": {"type": "string", "minLength": 20, "description": "知识点正文摘要（可引用 wiki 页面）"},
              "wikiPath": {"type": "string", "description": "对应 wiki 页面相对路径，如 concept/三位一体框架.md"},
              "rules": {
                "type": "array",
                "items": {"type": "string"},
                "minItems": 1,
                "maxItems": 10,
                "description": "核心规则/原则清单（3-8 条为宜）"
              },
              "prerequisites": {
                "type": "array",
                "items": {"type": "string", "pattern": "^K\\d{3}$"},
                "description": "前置知识点 id，形成学习路径"
              },
              "related": {
                "type": "array",
                "items": {"type": "string", "pattern": "^K\\d{3}$"},
                "description": "相关知识点（非前置）"
              },
              "authorId": {"type": "string", "pattern": "^P\\d+$"}
            }
          }
        },

        "Theme": {
          "type": "array",
          "description": "板块/题材实体（BFO continuant）。appearanceDays<3 且 rounds<2 的短命题材也可作为实例存在，但不升格为 wiki/sector/ 页面。",
          "items": {
            "type": "object",
            "required": ["id", "name", "category", "emotionStage", "appearanceDays"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^T\\d+(_\\d+)?$"},
              "name": {"type": "string"},
              "parentId": {
                "type": ["string", "null"],
                "pattern": "^T\\d+$",
                "description": "父板块 id；子题材 parentId 指向父板块，自身不建 wiki 页面"
              },
              "industryGroup": {"type": "string", "description": "产业群（如 AI算力硬件、周期资源、医药消费）"},
              "logicType": {
                "type": "string",
                "enum": ["实质性", "情绪性"],
                "description": "逻辑类型，对齐域1受控词汇"
              },
              "category": {"type": "string"},
              "tags": {"type": "array", "items": {"type": "string"}},
              "emotionStage": {
                "type": "string",
                "enum": ["启动期", "发酵期", "高潮期", "分歧期", "回流期", "退潮期", "休眠"],
                "description": "当前情绪周期阶段（对齐情绪周期理论 6 阶段 + 休眠）。注意：顺序为 启动→发酵→高潮→分歧→回流→退潮，分歧在高潮之后。"
              },
              "emotionPathRecent3Days": {
                "type": "array",
                "maxItems": 3,
                "items": {"type": "string", "enum": ["启动期", "发酵期", "高潮期", "分歧期", "回流期", "退潮期", "休眠"]},
                "description": "近三日阶段路径（由远及近），用于判断方向（升温/降温/延续）"
              },
              "appearanceDays": {"type": "integer", "minimum": 1},
              "rounds": {
                "type": "integer",
                "minimum": 0,
                "description": "独立炒作轮次。appearanceDays≥3 且 rounds≥2 才升格 wiki/sector/ 页面。"
              },
              "promotedToWiki": {
                "type": "boolean",
                "default": false,
                "description": "是否已升格为 wiki/sector/ 档案卡页"
              },
              "wikiPath": {"type": "string"},
              "leaderStockId": {"type": ["string", "null"], "pattern": "^ST\\d{3}$"},
              "currentStockIds": {
                "type": "array",
                "items": {"type": "string", "pattern": "^ST\\d{3}$"},
                "description": "本轮活跃成分股；对应档案卡'成分个股热度'表"
              }
            }
          }
        },

        "Stock": {
          "type": "array",
          "description": "个股实体。数据层可与 Theme 多对多关联，但 wiki 页面中不生成 个股↔板块 双向链接（对齐 organization-schema link_rules）。",
          "items": {
            "type": "object",
            "required": ["id", "name", "themeIds"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^ST\\d{3}$"},
              "name": {"type": "string"},
              "code": {
                "type": ["string", "null"],
                "pattern": "^\\d{6}$",
                "description": "6 位证券代码；港股/北交所等非 6 位可填 null"
              },
              "boardType": {
                "type": "string",
                "enum": ["主板", "创业板", "科创板", "北交所", "港股"]
              },
              "tags": {"type": "array", "items": {"type": "string"}},
              "mentionCount": {
                "type": "integer",
                "minimum": 0,
                "description": "累计被直播提及次数，用于热度排序"
              },
              "firstMentionDate": {"type": "string", "format": "date"},
              "lastMentionDate": {"type": "string", "format": "date"},
              "themeIds": {
                "type": "array",
                "items": {"type": "string", "pattern": "^T\\d+(_\\d+)?$"},
                "minItems": 1
              },
              "wikiPath": {
                "type": ["string", "null"],
                "description": "wiki 页面路径（entity/xxx.md）；仅高频/关键个股建页"
              }
            }
          }
        },

        "TradingDay": {
          "type": "array",
          "description": "交易日（直播内容容器）。sections 字段对齐 organization-schema 的六槽 + 技巧点拨槽。",
          "items": {
            "type": "object",
            "required": ["id", "date", "weekday", "marketState", "sections"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^D\\d{8}$"},
              "date": {"type": "string", "format": "date"},
              "weekday": {"type": "string", "enum": ["周一", "周二", "周三", "周四", "周五"]},
              "marketState": {
                "type": "string",
                "enum": ["强势震荡", "主升", "弱势震荡", "下降", "分化", "修复"],
                "description": "当日大势定性（对齐域1大势四态 + 扩展状态）"
              },
              "mainThemeIds": {
                "type": "array",
                "items": {"type": "string", "pattern": "^T\\d+(_\\d+)?$"},
                "description": "当日主线板块 id"
              },
              "wikiPath": {"type": "string", "description": "对应 summaries/投顾课直播-YYYYMMDD.md"},
              "sections": {
                "type": "object",
                "description": "按直播内容功能分槽（时间序）。槽键对齐六槽+skills，键名固定便于跨日对比。",
                "required": ["premarket_news", "premarket_plan", "auction_moves", "intraday_broadcast", "key_opportunities", "evening_review"],
                "additionalProperties": false,
                "properties": {
                  "premarket_news": {
                    "type": "string",
                    "description": "盘前消息（08:00-09:15，老师点评过的）"
                  },
                  "premarket_plan": {
                    "type": "string",
                    "description": "盘前交易计划（09:15-09:30，昨日推演+当日预案）"
                  },
                  "auction_moves": {
                    "type": "string",
                    "description": "竞价异动（09:20-09:25）"
                  },
                  "intraday_broadcast": {
                    "type": "string",
                    "description": "盘中实时播报（09:30-15:00，带 HH:MM 时间戳）"
                  },
                  "key_opportunities": {
                    "type": "string",
                    "description": "盘中重点交易机会（从播报提炼，含方向/依据/模式识别）"
                  },
                  "evening_review": {
                    "type": "string",
                    "description": "晚间复盘（19:00-22:00，定性+主线+连板+次日展望）"
                  },
                  "skills": {
                    "type": ["string", "null"],
                    "description": "技巧点拨/方法论教学段落（可空）"
                  }
                }
              }
            }
          }
        },

        "Catalyst": {
          "type": "array",
          "description": "催化事件（BFO occurrent）。对应板块档案卡'关联催化'表，由近及远倒序。",
          "items": {
            "type": "object",
            "required": ["id", "themeId", "date", "content", "marketReaction"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^C\\d+$"},
              "themeId": {"type": "string", "pattern": "^T\\d+(_\\d+)?$"},
              "date": {"type": "string", "format": "date"},
              "type": {
                "type": "string",
                "enum": ["宏观政策", "产业事件", "业绩", "机构观点", "盘面信号", "消息刺激", "技术路线", "其他"]
              },
              "content": {"type": "string"},
              "marketReaction": {
                "type": "string",
                "description": "市场反应描述（如'3 日短炒'、'集体加速开启一轮主升'）"
              },
              "tradingDayId": {"type": "string", "pattern": "^D\\d{8}$"}
            }
          }
        },

        "KnowledgeCase": {
          "type": "array",
          "description": "案例实例：K（知识点）↔ D（交易日）↔ ST（个股，可空）↔ 槽位 关联表。用于案例查询与模式页案例回流。",
          "items": {
            "type": "object",
            "required": ["id", "knowledgeId", "dayId", "sectionKey", "detail"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^KC\\d{4}$"},
              "knowledgeId": {"type": "string", "pattern": "^K\\d{3}$"},
              "stockId": {"type": ["string", "null"], "pattern": "^ST\\d{3}$"},
              "themeId": {"type": ["string", "null"], "pattern": "^T\\d+(_\\d+)?$"},
              "dayId": {"type": "string", "pattern": "^D\\d{8}$"},
              "sectionKey": {
                "type": "string",
                "enum": ["premarket_news", "premarket_plan", "auction_moves", "intraday_broadcast", "key_opportunities", "evening_review", "skills"],
                "description": "对应 TradingDay.sections 的槽键"
              },
              "detail": {"type": "string", "minLength": 10},
              "teacherQuote": {"type": ["string", "null"], "description": "老师原话（可空）"},
              "outcome": {
                "type": "string",
                "enum": ["成功", "失败", "待定"],
                "description": "案例结局标签，用于后续胜率统计"
              }
            }
          }
        }

      }
    }
  }
}
