const { UUID, UUIDV4, STRING, BOOLEAN, DATE } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
	const Concerns = sequelize.define(
		'Concerns',
		{
			id: {
				type: UUID,
				defaultValue: UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			type: {
				type: STRING,
				allowNull: false,
			},
			member_id: {
				type: UUID,
				allowNull: true,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			is_resolved: {
				type: BOOLEAN,
				defaultValue: false,
			},
			createdAt: {
				type: DATE,
				allowNull: false,
			},
		},
		{
			tableName: 'concerns',
			updatedAt: false,
		},
	);

	Concerns.associate = (models) => {
		Concerns.hasMany(models.ConcernMessages, {
			foreignKey: 'concernId',
			as: 'messages',
			onDelete: 'CASCADE',
		});
	};

	return Concerns;
};
