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

module.exports = (sequelize) => {
    const CourseVideo = sequelize.define('coursevideo', {
        course_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'courses',
                key: 'id',
                primaryKey: true
            }
        },
        video_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'videos',
                key: 'id',
                primaryKey: true
            }
        }
    }, {
        tableName: 'coursevideos',
    }, {
        freezeTableName: true
    });

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

        /**
         * Associate CourseVideo with Video
         * @param {object} models - The models to associate with.
         * @property {object} video - The Video model associated with CourseVideo.
         */
        CourseVideo.belongsTo(models.Video, {
            foreignKey: 'video_id',
            as: 'video'
        });
    };

    return CourseVideo;
};