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

class VocabGrammarExerciseProgress extends Model {}

VocabGrammarExerciseProgress.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    userId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'user_id'
    },
    exerciseId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'exercise_id'
    },
    attempts: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0
    },
    correctAttempts: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        field: 'correct_attempts'
    },
    lastAttemptAt: {
        type: DataTypes.DATE,
        allowNull: true,
        field: 'last_attempt_at'
    },
    completed: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false
    },
    completedAt: {
        type: DataTypes.DATE,
        allowNull: true,
        field: 'completed_at'
    }
}, {
    sequelize,
    modelName: 'VocabGrammarExerciseProgress',
    tableName: 'vocab_grammar_exercise_progress',
    schema: 'community',
    timestamps: false,
    underscored: true
});

export default VocabGrammarExerciseProgress;
