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

module.exports = (sequelize, DataTypes) => {
	const PostImages = sequelize.define(
		'PostImages',
		{
			id: {
				type: UUID,
				defaultValue: UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			post_id: {
				type: UUID,
				allowNull: false,
			},
			image: {
				type: STRING,
				allowNull: false,
			},
		},
		{
			tableName: 'post_images',
			timestamps: false,
		},
	);

	PostImages.associate = (models) => {
		PostImages.belongsTo(models.Posts, {
			foreignKey: 'post_id',
			as: 'post',
			onDelete: 'CASCADE',
		});
	};

	return PostImages;
};
