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

module.exports = (sequelize) => {
    const EmployeeGroupTable = sequelize.define('employeegrouptable', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        creation: { type: DataTypes.DATE, allowNull: false },
        modified: { type: DataTypes.DATE, allowNull: false },
        modified_by: { type: DataTypes.INTEGER, allowNull: false },
        owner: { type: DataTypes.INTEGER, allowNull: false },

        // main
        employeegroup_id: { type: DataTypes.INTEGER, allowNull: false },
        employee_id: { type: DataTypes.INTEGER, allowNull: false },
        user_id: { type: DataTypes.INTEGER, allowNull: false },

        // fk
        company_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
        },
    }, {
        tableName: 'employeegrouptables',
        freezeTableName: true
    });

    /**
     * Associates the EmployeeGroupTable model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    EmployeeGroupTable.associate = (models) => {
        EmployeeGroupTable.belongsTo(models.EmployeeGroup, { as: 'employeegroup', foreignKey: 'employeegroup_id' });
        EmployeeGroupTable.belongsTo(models.Company, { as: 'company', foreignKey: 'company_id' });
        EmployeeGroupTable.belongsTo(models.Employee, { as: 'employee', foreignKey: 'employee_id' });
        EmployeeGroupTable.belongsTo(models.User, { as: 'user', foreignKey: 'user_id' });
    };

    return EmployeeGroupTable;
};
