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

module.exports = (sequelize) => {
    const CourseDevelopment = sequelize.define('coursedevelopment', {
        course_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'courses',
                key: 'id',
                primaryKey: true
            }
        },
        development_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'developments',
                key: 'id',
                primaryKey: true
            }
        }
    }, {
        tableName: 'coursedevelopments',
        freezeTableName: true
    });

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

        /**
         * Associates the CourseDevelopment model with other models.
         * @param {object} models - The models to associate with.
         * @property {object} development - The Development model associated with CourseDevelopment.
         */
        CourseDevelopment.belongsTo(models.Development, {
            foreignKey: 'development_id',
            as: 'development'
        });
    };

    return CourseDevelopment;
};
