/**
 * M1 课标（Standards）模块 - 类型定义
 *
 * 支持国家标准 / 课标 / 自定义三层级课标库。
 * 课案通过 lessonPlanStandards 关联表实现多对多关系。
 */

import type { StandardLevel } from "../lesson-preparation/lib/type-guards";

/** 课标节点 */
export interface Standard {
  id: string;
  code: string;
  title: string;
  description?: string;
  level: StandardLevel;
  parentId?: string;
  subjectId?: string;
  gradeId?: string;
  /** 学段：primary / junior_high / senior_high */
  stage?: string;
  sortOrder: number;
  isActive: boolean;
  createdBy?: string;
  createdAt: Date;
  updatedAt: Date;
}

/** 课标树节点（带子节点） */
export interface StandardTreeNode extends Standard {
  children: StandardTreeNode[];
}

/** 课案 ↔ 课标 关联 */
export interface LessonPlanStandardLink {
  id: string;
  planId: string;
  standardId: string;
  /** 关联类型：primary（主要对标）/ related（相关对标） */
  relationType: "primary" | "related";
  createdBy: string;
  createdAt: Date;
  /** 关联的课标详情（join 查询时填充） */
  standard?: Standard;
}

/** 课案课标覆盖度统计 */
export interface LessonPlanStandardsCoverage {
  planId: string;
  totalStandards: number;
  primaryCount: number;
  relatedCount: number;
  coveragePercent: number;
}

/** 课标查询参数 */
export interface GetStandardsParams {
  level?: StandardLevel;
  parentId?: string;
  subjectId?: string;
  gradeId?: string;
  stage?: string;
  includeInactive?: boolean;
  /** 是否返回树形结构 */
  asTree?: boolean;
}

/** 课标导入参数 */
export interface ImportStandardsInput {
  standards: Array<{
    code: string;
    title: string;
    description?: string;
    level: StandardLevel;
    parentId?: string;
    subjectId?: string;
    gradeId?: string;
    stage?: string;
    sortOrder?: number;
  }>;
  /** 导入策略：skip（跳过已存在）/ update（更新已存在）/ fail（重复则失败） */
  conflictStrategy?: "skip" | "update" | "fail";
}
