module.exports = (sequelize, DataTypes) => {
	const ProductImages = sequelize.define(
		'ProductImages',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			product_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'products',
					key: 'id',
				},
			},
			image: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			category: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			type: {
				type: DataTypes.ENUM('size', 'color'),
				allowNull: false,
				defaultValue: 'color',
			},
		},
		{
			tableName: 'product_images',
			timestamps: false,
		},
	);

	ProductImages.associate = (models) => {
		ProductImages.belongsTo(models.Products, {
			foreignKey: 'product_id',
			as: 'product',
		});
	};

	return ProductImages;
};
