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

class VocabCourseLesson extends Model {}

VocabCourseLesson.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    courseId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'course_id'
    },
    chapterId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        field: 'chapter_id'
    },
    lessonNumber: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'lesson_number'
    },
    title: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    description: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    weekNumber: {
        type: DataTypes.INTEGER,
        allowNull: true,
        field: 'week_number'
    },
    dayNumber: {
        type: DataTypes.INTEGER,
        allowNull: true,
        field: 'day_number'
    },
    lessonType: {
        type: DataTypes.TEXT,
        allowNull: false,
        defaultValue: 'vocab',
        field: 'lesson_type'
    },
    audioUrl: {
        type: DataTypes.TEXT,
        allowNull: true,
        field: 'audio_url'
    },
    culturalNotes: {
        type: DataTypes.TEXT,
        allowNull: true,
        field: 'cultural_notes'
    },
    targetMinutes: {
        type: DataTypes.INTEGER,
        allowNull: true,
        field: 'target_minutes'
    },
    targetScorePercent: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 80,
        field: 'target_score_percent'
    },
    requiresReview: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        field: 'requires_review'
    },
    createdAt: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
        field: 'created_at'
    }
}, {
    sequelize,
    modelName: 'VocabCourseLesson',
    tableName: 'vocab_course_lesson',
    schema: 'community',
    timestamps: false,
    underscored: true
});

export default VocabCourseLesson;
