import { z } from "zod"
import type { StatusVariantMap } from "@/shared/components/ui/status-badge"
import { QuestionTypeEnum } from "./schema"

export type { QuestionContent, QuestionOption } from "./utils/parse-content"

export type QuestionType = z.infer<typeof QuestionTypeEnum>

/** 题型 → Badge variant 映射 */
export const QUESTION_TYPE_VARIANT: StatusVariantMap<QuestionType> = {
  single_choice: "default",
  multiple_choice: "secondary",
  judgment: "outline",
  text: "secondary",
  composite: "secondary",
}

/** 题型 → i18n 键映射（供 useTranslations 使用） */
export const QUESTION_TYPE_I18N_KEY: Record<QuestionType, string> = {
  single_choice: "type.single_choice",
  multiple_choice: "type.multiple_choice",
  judgment: "type.judgment",
  text: "type.text",
  composite: "type.composite",
}

/** 难度 → i18n 键映射 */
export const DIFFICULTY_I18N_KEY: Record<number, string> = {
  1: "difficulty.1",
  2: "difficulty.2",
  3: "difficulty.3",
  4: "difficulty.4",
  5: "difficulty.5",
}

export interface Question {
  id: string
  content: unknown
  type: QuestionType
  difficulty: number
  createdAt: Date
  updatedAt: Date
  author: {
    id: string
    name: string | null
    image: string | null
  } | null
  knowledgePoints: {
    id: string
    name: string
  }[]
  childrenCount?: number
}

export type KnowledgePointOption = {
  id: string
  name: string
  chapterId: string | null
  chapterTitle: string | null
  textbookId: string | null
  textbookTitle: string | null
  subject: string | null
  grade: string | null
}

/** 教材选项（级联筛选第一级） */
export type TextbookOption = {
  id: string
  title: string
  subject: string
  grade: string | null
}

/** 章节选项（级联筛选第二级） */
export type ChapterOption = {
  id: string
  title: string
  parentId: string | null
  /** 层级深度，用于缩进显示 */
  depth: number
}
