{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://fupan-ge-wiki.pages.dev/spec/schema/organization-schema.json",
  "title": "FupanGe Wiki Organization Schema",
  "description": "复盘哥交易知识库 — 组织规范层 JSON Schema v2.0。定义 wiki 如何分域、页面模板、链接纪律、维护流程。与 instance-schema.json（实例数据层）配合使用：规范层管'怎么组织'，数据层管'存什么'。",
  "type": "object",
  "required": ["meta", "domains", "domainRelations", "pageSchemas", "linkRules", "maintenanceWorkflow", "controlledVocabulary"],
  "additionalProperties": false,

  "meta": {
    "type": "object",
    "required": ["name", "version", "definedAt", "sourceOfTruth", "samplePage"],
    "additionalProperties": false,
    "properties": {
      "name": {"const": "FupanGe Wiki Organization Schema"},
      "version": {"const": "2.0.0"},
      "definedAt": {"type": "string", "format": "date"},
      "sourceOfTruth": {
        "type": "string",
        "description": "人类可读的事实来源 Markdown 文件",
        "default": "wiki/overview/本体论框架.md"
      },
      "companionInstanceSchema": {
        "type": "string",
        "default": "wiki/overview/schema/instance-schema.json",
        "description": "配套的实例数据层 schema"
      },
      "samplePage": {"type": "string", "default": "wiki/sector/光模块.md"},
      "standardsMapping": {
        "type": "object",
        "description": "本框架与官方本体标准的对照。本框架是 BFO（ISO/IEC 21838-2:2021）与 W3C SKOS 的 Markdown 轻量实现，非形式化 OWL 本体。",
        "additionalProperties": false,
        "properties": {
          "domain1": {"type": "string", "const": "SKOS ConceptScheme（TBox：术语层+推理规则）"},
          "domain2": {"type": "string", "const": "BFO domain ontology（continuant 实体 + occurrent 事件分离）"},
          "domain3": {"type": "string", "const": "ABox（带时间戳的断言流）"},
          "correspondences": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["wiki_term", "standard"],
              "additionalProperties": false,
              "properties": {
                "wiki_term": {"type": "string"},
                "standard": {"type": "string"}
              }
            }
          }
        }
      }
    }
  },

  "domains": {
    "type": "object",
    "required": ["domain1_methodology", "domain2_sector", "domain3_live_content"],
    "additionalProperties": false,
    "description": "三域模型：知识按性质分为三类，互不混装。",
    "properties": {

      "domain1_methodology": {
        "type": "object",
        "required": ["name", "essence", "stability", "directories", "role"],
        "additionalProperties": false,
        "properties": {
          "name": {"const": "方法论域"},
          "essence": {"const": "词汇表 + 推理规则"},
          "stability": {"const": "稳定，越沉淀越浓缩"},
          "role": {"type": "string", "const": "提供谓词（周期阶段/主线/逻辑类型/节点/模式/仓位分级），是图谱枢纽"},
          "directories": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1,
            "uniqueItems": true
          },
          "constraints": {
            "type": "array",
            "items": {"type": "string"}
          }
        }
      },

      "domain2_sector": {
        "type": "object",
        "required": ["name", "essence", "stability", "directories", "role", "pageCreationThreshold", "tierMaintenance"],
        "additionalProperties": false,
        "properties": {
          "name": {"const": "板块域"},
          "essence": {"const": "承载状态的中期实体（BFO continuant）"},
          "stability": {"const": "中期稳定，状态随周期演化"},
          "role": {"const": "方法论谓词的着陆点；炒作事件（occurrent）作为行记录在档案卡内"},
          "directories": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "pageCreationThreshold": {
            "type": "object",
            "required": ["create_page", "no_page", "sub_theme"],
            "additionalProperties": false,
            "properties": {
              "create_page": {"type": "string", "description": "建页条件，如 ≥3 日提及且 ≥2 轮独立炒作"},
              "no_page": {"type": "string"},
              "sub_theme": {"type": "string"}
            }
          },
          "tierMaintenance": {
            "type": "object",
            "required": ["A", "B", "C"],
            "additionalProperties": false,
            "properties": {
              "A": {"$ref": "#/definitions/tierSpec"},
              "B": {"$ref": "#/definitions/tierSpec"},
              "C": {"$ref": "#/definitions/tierSpec"}
            }
          }
        }
      },

      "domain3_live_content": {
        "type": "object",
        "required": ["name", "essence", "stability", "directories", "role", "specialRules"],
        "additionalProperties": false,
        "properties": {
          "name": {"const": "直播内容域"},
          "essence": {"const": "带时间戳的观测记录（ABox）"},
          "stability": {"const": "当日有效，过时即归档"},
          "role": {"const": "每日观测流；跨日聚合视图是域内索引而非独立层；'私密/公开'仅为可见性属性"},
          "directories": {"type": "array", "items": {"type": "string"}},
          "specialRules": {
            "type": "array",
            "items": {"type": "string"},
            "description": "个股页不与板块互链、大势定性归域3 等特殊规则"
          }
        }
      }

    }
  },

  "domainRelations": {
    "type": "array",
    "description": "三域间的单向依赖。",
    "items": {
      "type": "object",
      "required": ["from", "to", "type", "mechanism"],
      "additionalProperties": false,
      "properties": {
        "from": {"type": "string", "enum": ["domain1_methodology", "domain2_sector", "domain3_live_content"]},
        "to": {"type": "string", "enum": ["domain1_methodology", "domain2_sector", "domain3_live_content"]},
        "type": {"type": "string", "enum": ["provides_predicates", "observed_in", "case_feedback"]},
        "mechanism": {"type": "string"}
      }
    }
  },

  "pageSchemas": {
    "type": "object",
    "required": ["sectorPage", "dailySummary"],
    "additionalProperties": false,
    "properties": {

      "sectorPage": {
        "type": "object",
        "required": ["description", "sections", "dataSources"],
        "additionalProperties": false,
        "properties": {
          "description": {"type": "string", "const": "域2板块档案卡四段式模板（概览+近三日+催化+个股热度+相关方法论）"},
          "sections": {
            "type": "array",
            "items": {
              "oneOf": [
                {"$ref": "#/definitions/sectionOverview"},
                {"$ref": "#/definitions/sectionRecent3Day"},
                {"$ref": "#/definitions/sectionCatalysts"},
                {"$ref": "#/definitions/sectionStockHeat"},
                {"$ref": "#/definitions/sectionRelatedMethodology"}
              ]
            },
            "minItems": 5,
            "maxItems": 5
          },
          "dataSources": {
            "type": "object",
            "additionalProperties": {"type": "string"}
          }
        }
      },

      "dailySummary": {
        "type": "object",
        "required": ["description", "slots", "legacyMapping"],
        "additionalProperties": false,
        "properties": {
          "description": {"type": "string"},
          "slots": {
            "type": "array",
            "items": {"$ref": "#/definitions/slotDef"},
            "minItems": 7,
            "maxItems": 7
          },
          "legacyMapping": {
            "type": "object",
            "additionalProperties": {"type": "string"}
          }
        }
      }

    }
  },

  "linkRules": {
    "type": "object",
    "required": ["description", "rules", "sectorMap"],
    "additionalProperties": false,
    "properties": {
      "description": {"type": "string"},
      "rules": {
        "type": "array",
        "items": {
          "type": "object",
          "required": ["type", "rule"],
          "additionalProperties": false,
          "properties": {
            "type": {"type": "string"},
            "rule": {"type": "string"},
            "severity": {"type": "string", "enum": ["error", "warning", "info"], "default": "info"}
          }
        }
      },
      "sectorMap": {
        "type": "object",
        "required": ["file", "format"],
        "additionalProperties": false,
        "properties": {
          "file": {"type": "string"},
          "format": {"type": "string"}
        }
      }
    }
  },

  "maintenanceWorkflow": {
    "type": "object",
    "required": ["daily", "weekly", "newTheme", "graphOutput"],
    "additionalProperties": false,
    "properties": {
      "daily": {"type": "string"},
      "weekly": {"type": "string"},
      "newTheme": {"type": "string"},
      "graphOutput": {"type": "string"}
    }
  },

  "controlledVocabulary": {
    "type": "object",
    "description": "域1方法论的受控词汇表（谓词枚举），所有板块页/摘要页的状态标签必须从这里取值。",
    "additionalProperties": {
      "type": "array",
      "items": {"type": "string"}
    }
  },

  "pendingMerges": {
    "type": "array",
    "description": "待合并的重复页面。",
    "items": {
      "type": "object",
      "required": ["merge", "into"],
      "additionalProperties": false,
      "properties": {
        "merge": {
          "oneOf": [
            {"type": "string"},
            {"type": "array", "items": {"type": "string"}}
          ]
        },
        "into": {"type": "string"}
      }
    }
  },

  "knownDataIssues": {
    "type": "array",
    "items": {"type": "string"}
  },

  "changelog": {
    "type": "array",
    "items": {
      "type": "object",
      "required": ["date", "version", "changes"],
      "additionalProperties": false,
      "properties": {
        "date": {"type": "string", "format": "date"},
        "version": {"type": "string"},
        "changes": {"type": "string"}
      }
    }
  },

  "definitions": {

    "tierSpec": {
      "type": "object",
      "required": ["criteria", "action"],
      "additionalProperties": false,
      "properties": {
        "criteria": {"type": "string"},
        "action": {"type": "string"}
      }
    },

    "sectionOverview": {
      "type": "object",
      "required": ["id", "title", "layers", "updateTriggers"],
      "additionalProperties": false,
      "properties": {
        "id": {"const": "overview"},
        "title": {"const": "概览"},
        "layers": {
          "type": "object",
          "required": ["identity", "cognition"],
          "additionalProperties": false,
          "properties": {
            "identity": {
              "type": "object",
              "required": ["stability", "fields"],
              "additionalProperties": false,
              "properties": {
                "stability": {"type": "string"},
                "fields": {"type": "array", "items": {"type": "string"}}
              }
            },
            "cognition": {
              "type": "object",
              "required": ["stability", "fields"],
              "additionalProperties": false,
              "properties": {
                "stability": {"type": "string"},
                "fields": {"type": "array", "items": {"type": "string"}}
              }
            }
          }
        },
        "updateTriggers": {"type": "array", "items": {"type": "string"}}
      }
    },

    "sectionRecent3Day": {
      "type": "object",
      "required": ["id", "title", "window", "columns", "dormantDisplay"],
      "additionalProperties": false,
      "properties": {
        "id": {"const": "recent_3day_status"},
        "title": {"const": "近三日情绪周期状态"},
        "window": {"type": "string"},
        "columns": {"type": "array", "items": {"type": "string"}},
        "dormantDisplay": {"type": "string"}
      }
    },

    "sectionCatalysts": {
      "type": "object",
      "required": ["id", "title", "order", "columns", "maintenance"],
      "additionalProperties": false,
      "properties": {
        "id": {"const": "catalysts"},
        "title": {"const": "关联催化"},
        "order": {"type": "string"},
        "columns": {"type": "array", "items": {"type": "string"}},
        "maintenance": {"type": "string"}
      }
    },

    "sectionStockHeat": {
      "type": "object",
      "required": ["id", "title", "sort", "columns", "notes"],
      "additionalProperties": false,
      "properties": {
        "id": {"const": "stock_heat"},
        "title": {"const": "成分个股热度"},
        "sort": {"type": "string"},
        "columns": {"type": "array", "items": {"type": "string"}},
        "notes": {"type": "string"}
      }
    },

    "sectionRelatedMethodology": {
      "type": "object",
      "required": ["id", "title", "constraint"],
      "additionalProperties": false,
      "properties": {
        "id": {"const": "related_methodology"},
        "title": {"const": "相关方法论"},
        "constraint": {"type": "string"}
      }
    },

    "slotDef": {
      "type": "object",
      "required": ["id", "title", "timeRange", "criteria"],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "enum": ["premarket_news", "premarket_plan", "auction_moves", "intraday_broadcast", "key_opportunities", "evening_review", "skills"]
        },
        "title": {"type": "string"},
        "timeRange": {"type": "string"},
        "criteria": {"type": "string"}
      }
    }

  }
}
