const { DataTypes } = require("sequelize");
const sequelize = require("../db");

const TrainingQuiz = sequelize.define("TrainingQuiz", {
  question: {
    type: DataTypes.TEXT,
    allowNull: false,
  },
  options: {
    type: DataTypes.JSON,
    allowNull: false,
    comment: "Array of answer options",
  },
  correctAnswer: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: "Index of correct option (0-based)",
  },
  explanation: {
    type: DataTypes.TEXT,
    comment: "Optional explanation for the answer",
  },
  order: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
  // TrainingModuleId added via association
}, {
  freezeTableName: true,
  tableName: 'TrainingQuizzes'
});

module.exports = TrainingQuiz;
