import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../utils/sequelize.js';

class VocabGrammarExercise extends Model {}

VocabGrammarExercise.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    lessonId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'lesson_id'
    },
    exerciseTypeId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'exercise_type_id'
    },
    exerciseNumber: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'exercise_number'
    },
    title: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    instruction: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    questionData: {
        type: DataTypes.JSONB,
        allowNull: false,
        field: 'question_data'
    },
    answerData: {
        type: DataTypes.JSONB,
        allowNull: false,
        field: 'answer_data'
    },
    explanation: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    createdByUserId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'created_by_user_id'
    },
    createdAt: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
        field: 'created_at'
    }
}, {
    sequelize,
    modelName: 'VocabGrammarExercise',
    tableName: 'vocab_grammar_exercise',
    schema: 'community',
    timestamps: false,
    underscored: true
});

export default VocabGrammarExercise;
