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

module.exports = (sequelize) => {
	const HotelRooms = sequelize.define(
		'HotelRooms',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'hotels',
					key: 'id',
				},
			},
			name: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			description: {
				type: DataTypes.TEXT('long'),
				allowNull: true,
			},
			additional_info: {
				type: DataTypes.JSON,
				allowNull: true,
			},
			price: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
			},
		},
		{
			tableName: 'hotel_rooms',
			timestamps: false,
		},
	);

	HotelRooms.associate = (models) => {
		HotelRooms.belongsTo(models.Hotels, {
			foreignKey: 'hotel_id',
			as: 'hotel',
		});

		HotelRooms.hasMany(models.HotelRoomImages, {
			foreignKey: 'hotel_room_id',
			as: 'images',
			onDelete: 'CASCADE',
		});

		HotelRooms.hasMany(models.HotelBookings, {
			foreignKey: 'hotel_room_id',
			as: 'bookings',
			onDelete: 'CASCADE',
		});

		HotelRooms.hasMany(models.HotelReviews, {
			foreignKey: 'hotel_room_id',
			as: 'reviews',
			onDelete: 'CASCADE',
		});
	};

	return HotelRooms;
};
