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

module.exports = (sequelize) => {
    const EmailAccountProject = sequelize.define('emailaccountproject', {
        emailaccount_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'emailaccounts',
                key: 'id',
                primaryKey: true
            },
        },
        project_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'projects',
                key: 'id',
                primaryKey: true
            },
        }
    }, {
        tableName: 'emailaccountprojects',
    }, {
        freezeTableName: true 
    });

    /**
     * Associates the EmailAccountProject model with other models.
     * @param {object} models - The models to associate with.
     */
    EmailAccountProject.associate = (models) => {
        /**
         * Associate EmailAccountProject with EmailAccount
         * @param {object} models - The models to associate with.
         * @param {object} models.EmailAccount - The EmailAccount model.
         */
        EmailAccountProject.belongsTo(models.EmailAccount, {
            foreignKey: 'emailaccount_id',
            as: 'emailaccount'
        });

        /**
         * Associate EmailAccountProject with Project
         * @param {object} models - The models to associate with.
         * @param {object} models.Project - The Project model.
         */
        EmailAccountProject.belongsTo(models.Project, {
            foreignKey: 'project_id',
            as: 'project'
        });
    };

    return EmailAccountProject;
};