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

module.exports = (sequelize) => {
    const CourseDocument = sequelize.define('coursedocument', {
        course_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'courses',
                key: 'id',
                primaryKey: true
            }
        },
        document_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'documents',
                key: 'id',
                primaryKey: true
            }
        }
    }, {
        tableName: 'coursedocuments',
    }, {
        freezeTableName: true
    });

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

        /**
         * Associates the CourseDocument model with other models.
         * @param {object} models - The models to associate with.
         * @property {object} document - The Document model associated with CourseDocument.
         */
        CourseDocument.belongsTo(models.Document, {
            foreignKey: 'document_id',
            as: 'document'
        });
    };

    return CourseDocument;
};