import { z } from "zod"

export const QuestionTypeEnum = z.enum(["single_choice", "multiple_choice", "text", "judgment", "composite"])

export const BaseQuestionSchema = z.object({
  content: z.unknown().describe("JSON content for the question (e.g. Slate nodes)"),
  type: QuestionTypeEnum,
  difficulty: z.number().min(1).max(5).default(1),
  knowledgePointIds: z.array(z.string()).optional(),
})

export type CreateQuestionInput = z.infer<typeof BaseQuestionSchema> & {
  subQuestions?: CreateQuestionInput[]
}

export const CreateQuestionSchema: z.ZodType<CreateQuestionInput> = BaseQuestionSchema.extend({
  subQuestions: z.lazy(() => CreateQuestionSchema.array().optional()),
})
