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

module.exports = (sequelize) => {
	const RestaurantSaves = sequelize.define(
		'RestaurantSaves',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			restaurant_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'restaurants',
					key: 'id',
				},
			},
			member_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
		},
		{
			tableName: 'restaurant_saves',
			timestamps: true,
			updatedAt: false,
		},
	);

	RestaurantSaves.associate = (models) => {
		RestaurantSaves.belongsTo(models.Restaurants, {
			foreignKey: 'restaurant_id',
			as: 'restaurant',
		});
		RestaurantSaves.belongsTo(models.Members, {
			foreignKey: 'member_id',
			as: 'member',
		});
	};

	return RestaurantSaves;
};
