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

module.exports = (sequelize) => {
	const RestaurantImages = sequelize.define(
		'RestaurantImages',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			restaurant_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'restaurants',
					key: 'id',
				},
			},
			image: {
				type: DataTypes.STRING,
				allowNull: false,
			},
		},
		{
			tableName: 'restaurant_images',
			timestamps: false,
		},
	);

	RestaurantImages.associate = (models) => {
		RestaurantImages.belongsTo(models.Restaurants, {
			foreignKey: 'restaurant_id',
			as: 'restaurant',
		});
	};

	return RestaurantImages;
};
