'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.createTable('hotels', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			name: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			description: {
				type: Sequelize.TEXT('long'),
				allowNull: true,
			},
			location: {
				type: Sequelize.TEXT('long'),
				allowNull: false,
			},

			contact: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			whats_app: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			email: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			viber: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			additional_info: {
				type: Sequelize.JSON,
				allowNull: true,
			},
			longitude: {
				type: Sequelize.DECIMAL(11, 8),
				allowNull: false,
			},
			latitude: {
				type: Sequelize.DECIMAL(10, 8),
				allowNull: false,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});

		await queryInterface.createTable('hotel_images', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotels',
					key: 'id',
				},
			},
			image: {
				type: Sequelize.STRING,
				allowNull: false,
			},
		});

		await queryInterface.createTable('hotel_rooms', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotels',
					key: 'id',
				},
			},
			name: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			description: {
				type: Sequelize.TEXT('long'),
				allowNull: true,
			},
			additional_info: {
				type: Sequelize.JSON,
				allowNull: true,
			},
			price: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
			},
		});

		await queryInterface.createTable('hotel_room_images', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_room_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotel_rooms',
					key: 'id',
				},
			},
			image: {
				type: Sequelize.STRING,
				allowNull: false,
			},
		});

		await queryInterface.createTable('hotel_bookings', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotels',
					key: 'id',
				},
			},
			hotel_room_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotel_rooms',
					key: 'id',
				},
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			check_in: {
				type: Sequelize.DATEONLY,
				allowNull: false,
			},
			check_out: {
				type: Sequelize.DATEONLY,
				allowNull: false,
			},
			price: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
			},
			duration: {
				type: Sequelize.INTEGER,
				allowNull: false,
			},
			total: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});

		await queryInterface.createTable('hotel_reviews', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotels',
					key: 'id',
				},
			},
			hotel_room_id: {
				type: Sequelize.UUID,
				allowNull: true,
				references: {
					model: 'hotel_rooms',
					key: 'id',
				},
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			rating: {
				type: Sequelize.INTEGER,
				allowNull: false,
			},
			content: {
				type: Sequelize.TEXT('long'),
				allowNull: true,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});

		await queryInterface.createTable('hotel_review_images', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			hotel_review_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'hotel_reviews',
					key: 'id',
				},
			},
			image: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.dropTable('hotel_review_images');
		await queryInterface.dropTable('hotel_reviews');
		await queryInterface.dropTable('hotel_bookings');
		await queryInterface.dropTable('hotel_room_images');
		await queryInterface.dropTable('hotel_rooms');
		await queryInterface.dropTable('hotel_images');
		await queryInterface.dropTable('hotels');
	},
};
