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

class VocabCourse extends Model {}

VocabCourse.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    ownerUserId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'owner_user_id'
    },
    title: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    description: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    languageId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        field: 'language_id'
    },
    nativeLanguageId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        field: 'native_language_id',
        comment: 'Muttersprache des Lerners (z.B. Deutsch, Englisch). NULL bedeutet "für alle Sprachen".'
    },
    difficultyLevel: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 1,
        field: 'difficulty_level'
    },
    isPublic: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        field: 'is_public'
    },
    shareCode: {
        type: DataTypes.TEXT,
        allowNull: true,
        unique: true,
        field: 'share_code'
    },
    createdAt: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
        field: 'created_at'
    },
    updatedAt: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
        field: 'updated_at'
    }
}, {
    sequelize,
    modelName: 'VocabCourse',
    tableName: 'vocab_course',
    schema: 'community',
    timestamps: true,
    underscored: true
});

export default VocabCourse;
