/**
 * Mock 知识图谱数据（core-edu / ai 域，P4 扩展）
 *
 * 包含数学、语文、英语三科知识点节点 + 前置依赖边。
 * 维护者：ai13（teacher-portal）
 */

import type { KnowledgeGraphData } from "@/lib/graphql-p4";

/** 全量知识图谱 mock（按科目分布，13 节点 + 10 边） */
export const mockKnowledgeGraph: KnowledgeGraphData = {
  nodes: [
    // ---- 数学（5 节点） ----
    {
      id: "math-01",
      name: "实数与运算",
      subject: "数学",
      description: "有理数、无理数、实数的基本运算",
      masteryLevel: 88,
    },
    {
      id: "math-02",
      name: "代数式",
      subject: "数学",
      description: "整式、分式、根式的化简与求值",
      masteryLevel: 76,
    },
    {
      id: "math-03",
      name: "方程与不等式",
      subject: "数学",
      description: "一元二次方程、不等式组求解",
      masteryLevel: 62,
    },
    {
      id: "math-04",
      name: "函数",
      subject: "数学",
      description: "一次函数、二次函数、指数对数函数",
      masteryLevel: 45,
    },
    {
      id: "math-05",
      name: "导数",
      subject: "数学",
      description: "导数的几何意义与运算应用",
      masteryLevel: 32,
    },
    // ---- 语文（4 节点） ----
    {
      id: "chinese-01",
      name: "文言文基础",
      subject: "语文",
      description: "常见实词虚词、句式辨析",
      masteryLevel: 81,
    },
    {
      id: "chinese-02",
      name: "古诗词鉴赏",
      subject: "语文",
      description: "意象、手法、情感分析",
      masteryLevel: 68,
    },
    {
      id: "chinese-03",
      name: "现代文阅读",
      subject: "语文",
      description: "论述类与文学类文本阅读策略",
      masteryLevel: 55,
    },
    {
      id: "chinese-04",
      name: "议论文写作",
      subject: "语文",
      description: "论点提炼、论据组织、论证结构",
      masteryLevel: 48,
    },
    // ---- 英语（4 节点） ----
    {
      id: "english-01",
      name: "词汇基础",
      subject: "英语",
      description: "核心 3500 词汇与词组搭配",
      masteryLevel: 90,
    },
    {
      id: "english-02",
      name: "语法结构",
      subject: "英语",
      description: "从句、非谓语动词、虚拟语气",
      masteryLevel: 72,
    },
    {
      id: "english-03",
      name: "阅读理解",
      subject: "英语",
      description: "主旨、细节、推理题型策略",
      masteryLevel: 58,
    },
    {
      id: "english-04",
      name: "书面表达",
      subject: "英语",
      description: "应用文与议论文写作模板",
      masteryLevel: 40,
    },
  ],
  edges: [
    // 数学依赖链：实数 → 代数式 → 方程 → 函数 → 导数
    { from: "math-01", to: "math-02", type: "PREREQUISITE" },
    { from: "math-02", to: "math-03", type: "PREREQUISITE" },
    { from: "math-03", to: "math-04", type: "PREREQUISITE" },
    { from: "math-04", to: "math-05", type: "PREREQUISITE" },
    // 语文依赖链：文言文 → 古诗词 → 现代文 → 写作
    { from: "chinese-01", to: "chinese-02", type: "PREREQUISITE" },
    { from: "chinese-02", to: "chinese-03", type: "RELATED" },
    { from: "chinese-03", to: "chinese-04", type: "PREREQUISITE" },
    // 英语依赖链：词汇 → 语法 → 阅读 → 写作
    { from: "english-01", to: "english-02", type: "PREREQUISITE" },
    { from: "english-02", to: "english-03", type: "RELATED" },
    { from: "english-03", to: "english-04", type: "PREREQUISITE" },
  ],
};

/** 可选科目列表 */
export const KNOWLEDGE_SUBJECTS = ["全部", "数学", "语文", "英语"] as const;

/**
 * 按科目过滤知识图谱
 * subject 为空、"全部" 或 undefined 时返回全量
 */
export function filterKnowledgeGraph(
  subject: string | null | undefined,
): KnowledgeGraphData {
  if (!subject || subject === "全部") {
    return mockKnowledgeGraph;
  }
  const nodes = mockKnowledgeGraph.nodes.filter(
    (n) => n.subject === subject,
  );
  const nodeIds = new Set(nodes.map((n) => n.id));
  const edges = mockKnowledgeGraph.edges.filter(
    (e) => nodeIds.has(e.from) && nodeIds.has(e.to),
  );
  return { nodes, edges };
}
