import mongoose, { Document, Schema } from 'mongoose';

export interface IQuestionDocument extends Document {
  question_text: string;
  option_a: string;
  option_b: string;
  option_c: string;
  option_d: string;
  correct_option: string;
  difficulty: 'easy' | 'medium' | 'hard';
  category: string | null;
  tags: string[];
  points: number;
  createdAt: Date;
  updatedAt: Date;
}

const questionSchema = new Schema<IQuestionDocument>(
  {
    question_text: { type: String, required: true, unique: true, trim: true },
    option_a: { type: String, required: true, trim: true },
    option_b: { type: String, required: true, trim: true },
    option_c: { type: String, required: true, trim: true },
    option_d: { type: String, required: true, trim: true },
    correct_option: { type: String, required: true, trim: true },
    difficulty: { type: String, enum: ['easy', 'medium', 'hard'], default: 'medium' },
    category: { type: String, trim: true, default: null },
    tags: { type: [String], default: [] },
    points: { type: Number, default: 1 },
  },
  { timestamps: true },
);

export default mongoose.model<IQuestionDocument>('Question', questionSchema);
