import { z } from "zod";

export const questionTypeSchema = z.enum([
  "single_choice",
  "multiple_choice",
  "short_answer",
  "essay",
]);

export const questionSourceSchema = z.enum([
  "manual",
  "ai_generated",
  "imported",
]);

export const createQuestionSchema = z.object({
  knowledgePointId: z.string().min(1).max(32),
  type: questionTypeSchema,
  content: z.string().min(1),
  options: z.record(z.unknown()).nullish(),
  answer: z.string().min(1),
  explanation: z.string().optional(),
  difficulty: z.number().int().min(1).max(5).optional().default(3),
  source: questionSourceSchema.optional().default("manual"),
  createdBy: z.string().min(1).max(32),
  metadata: z.record(z.unknown()).nullish(),
});

export const updateQuestionSchema = z.object({
  content: z.string().min(1).optional(),
  options: z.record(z.unknown()).nullish(),
  answer: z.string().min(1).optional(),
  explanation: z.string().optional(),
  difficulty: z.number().int().min(1).max(5).optional(),
  status: z
    .enum(["draft", "pending_review", "published", "rejected", "archived"])
    .optional(),
});

export const listQuestionsSchema = z.object({
  knowledgePointId: z.string().optional(),
  type: questionTypeSchema.optional(),
  difficulty: z.coerce.number().int().min(1).max(5).optional(),
  status: z.string().optional(),
  page: z.coerce.number().int().min(1).default(1),
  pageSize: z.coerce.number().int().min(1).max(100).default(20),
});

export type CreateQuestionDto = z.infer<typeof createQuestionSchema>;
export type UpdateQuestionDto = z.infer<typeof updateQuestionSchema>;
export type ListQuestionsDto = z.infer<typeof listQuestionsSchema>;
