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

module.exports = (sequelize) => {
	const EmailGroupMember = sequelize.define(
		"emailgroupmember",
		{
			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 },

			email_group_id: { type: DataTypes.INTEGER, allowNull: false },
			employee_id: { type: DataTypes.INTEGER, allowNull: false },
			company_id: { type: DataTypes.INTEGER, allowNull: true },
		},
		{
			tableName: "email_group_members",
			freezeTableName: true,
		}
	);

	EmailGroupMember.associate = (models) => {
		EmailGroupMember.belongsTo(models.EmailGroup, { as: "emailgroup", foreignKey: "email_group_id" });
		EmailGroupMember.belongsTo(models.Company, { as: "company", foreignKey: "company_id" });
		EmailGroupMember.belongsTo(models.Employee, { as: "employee", foreignKey: "employee_id" });
	};

	return EmailGroupMember;
};
