const { UUID, UUIDV4, TEXT } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
	const PostComments = sequelize.define(
		'PostComments',
		{
			id: {
				type: UUID,
				defaultValue: UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			post_id: {
				type: UUID,
				allowNull: false,
			},
			member_id: {
				type: UUID,
				allowNull: false,
			},
			comment: {
				type: TEXT,
				allowNull: false,
			},
		},
		{
			tableName: 'post_comments',
			timestamps: true,
		},
	);

	PostComments.associate = (models) => {
		PostComments.belongsTo(models.Members, { as: 'member', foreignKey: 'member_id' });
		PostComments.hasMany(models.CommentLikes, { as: 'comment_likes', foreignKey: 'comment_id' });
	};

	return PostComments;
};
