<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBookingTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {


        DB::statement('SET FOREIGN_KEY_CHECKS=0');
        DB::statement('SET NAMES utf8mb4');

        DB::statement("
        CREATE TABLE `booking` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `property_id` int(10) unsigned NOT NULL,
  `channel_id` int(10) unsigned NOT NULL,
  `booking_code` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `search_key` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
  `channel_token` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `booking_engine_token` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `checkin_date` date NOT NULL,
  `checkout_date` date NOT NULL,
  `rooms` varchar(2550) COLLATE utf8mb4_unicode_ci NOT NULL,
  `payment_type_code` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL,
  `total` double(10,2) NOT NULL,
  `currency_code` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0:CancelRefund, 1:BookingConfirmed, 2:BookingPending-PreBooking',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_searchkey` (`search_key`),
  UNIQUE KEY `uq_bookingcode` (`booking_code`),
  KEY `property_id` (`property_id`),
  KEY `payment_type_code` (`payment_type_code`),
  KEY `currency_code` (`currency_code`),
  KEY `channel_id` (`channel_id`)
);
        ");

        DB::statement("
        CREATE TABLE `booking_contact` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `surname` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `phone_code` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone_number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `note` mediumtext COLLATE utf8mb4_unicode_ci,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `booking_id` (`booking_id`)
);
        ");

        DB::statement("
        CREATE TABLE `booking_payment` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `payment_code` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `payment_type_code` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL,
  `total` double(10,2) DEFAULT NULL,
  `currency_code` varchar(3) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0:CancelRefund, 1:Confirmed, 2:Pending',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `payment_type_code` (`payment_type_code`),
  KEY `booking_payment_ibfk_3` (`currency_code`)
);
        ");

        DB::statement("
        CREATE TABLE `booking_room` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `room_order_number` int(11) DEFAULT NULL,
  `occupancy_code` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `checkin_date` date NOT NULL,
  `checkout_date` date NOT NULL,
  `rate_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `rate_key_code` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `availability_id` int(10) unsigned NOT NULL,
  `availability_code` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `room_id` bigint(20) unsigned NOT NULL,
  `room_name` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `room_rate_mapping_id` int(20) unsigned NOT NULL,
  `room_rate_name` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cancellation_policy` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `payment_type_code` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL,
  `rate_detail` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `total` double(10,2) NOT NULL,
  `currency_code` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `booking_id` (`booking_id`),
  KEY `availability_id` (`availability_id`),
  KEY `room_id` (`room_id`),
  KEY `room_rate_id` (`room_rate_mapping_id`),
  KEY `payment_type_code` (`payment_type_code`),
  KEY `currency_code` (`currency_code`)
);
        ");


        DB::statement("
CREATE TABLE `booking_room_pax` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `booking_id` bigint(20) unsigned NOT NULL,
  `booking_room_id` bigint(20) unsigned NOT NULL,
  `type` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `surname` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `gender` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
  `citizen` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `birth_date` date NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `booking_id` (`booking_id`),
  KEY `booking_room_id` (`booking_room_id`)
);


        ");

        DB::statement("SET FOREIGN_KEY_CHECKS = 1;");

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

    }
}
