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

module.exports = (sequelize) => {
    const ProjectCourse = sequelize.define('projectcourse', {
        project_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'projects',
                key: 'id',
                primaryKey: true
            }
        },
        course_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'courses',
                key: 'id',
                primaryKey: true
            }
        }
    }, {
        tableName: 'projectcourses',
        freezeTableName: true
    });

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

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

    return ProjectCourse;
};
