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

module.exports = (sequelize) => {
	const Hotels = sequelize.define(
		'Hotels',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			name: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			description: {
				type: DataTypes.TEXT('long'),
				allowNull: true,
			},
			location: {
				type: DataTypes.TEXT('long'),
				allowNull: false,
			},
			contact: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			whats_app: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			email: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			viber: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			additional_info: {
				type: DataTypes.JSON,
				allowNull: true,
			},
			longitude: {
				type: DataTypes.DECIMAL(11, 8),
				allowNull: false,
			},
			latitude: {
				type: DataTypes.DECIMAL(10, 8),
				allowNull: false,
			},
			price: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
			},
			address: {
				type: DataTypes.STRING,
				allowNull: false,
			},
		},
		{
			tableName: 'hotels',
			timestamps: true,
		},
	);

	Hotels.associate = (models) => {
		Hotels.hasMany(models.HotelImages, {
			foreignKey: 'hotel_id',
			as: 'images',
			onDelete: 'CASCADE',
		});

		Hotels.hasMany(models.HotelRooms, {
			foreignKey: 'hotel_id',
			as: 'rooms',
			onDelete: 'CASCADE',
		});

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

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

	return Hotels;
};
