const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
    const CourseQuestionBank = sequelize.define('coursequestionbank', {
        course_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'courses',
                key: 'id',
                primaryKey: true
            }
        },
        questionbank_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'questionbanks',
                key: 'id',
                primaryKey: true
            }
        }
    }, {
        tableName: 'coursequestionbanks',
    }, {
        freezeTableName: true
    });

    /**
     * Associates the CourseQuestionBank model with other models.
     * @param {object} models - The models to associate with.
     */
    CourseQuestionBank.associate = (models) => {
        /**
         * Associate CourseQuestionBank with Course
         * @param {object} models - The models to associate with.
         * @property {object} course - The Course model associated with CourseQuestionBank.
         */
        CourseQuestionBank.belongsTo(models.Course, {
            foreignKey: 'course_id',
            as: 'course'
        });

        /**
         * Associate CourseQuestionBank with QuestionBank
         * @param {object} models - The models to associate with.
         * @property {object} questionBank - The QuestionBank model associated with CourseQuestionBank.
         */
        CourseQuestionBank.belongsTo(models.QuestionBank, {
            foreignKey: 'questionbank_id',
            as: 'questionbank'
        });
    };

    return CourseQuestionBank;
};
