<?php

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

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

        DB::statement("
        ALTER TABLE `property_cancellation_policy`
ADD COLUMN `before_arrival` int(10) UNSIGNED NOT NULL AFTER `name`,
ADD COLUMN `is_nonrefundable` tinyint(4) NOT NULL AFTER `before_arrival`,
ADD COLUMN `is_free_cancellation` tinyint(4) NOT NULL AFTER `is_nonrefundable`,
ADD COLUMN `type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'PER,FIX,NGT' AFTER `is_free_cancellation`,
ADD COLUMN `value` double(10, 2) NULL DEFAULT NULL AFTER `type`;

        ");


        DB::statement("

        UPDATE property_cancellation_policy SET
property_cancellation_policy.before_arrival = (SELECT property_cancellation_policy_setup.before_arrival FROM property_cancellation_policy_setup WHERE property_cancellation_policy_setup.cancellation_policy_id = property_cancellation_policy.id),
property_cancellation_policy.is_nonrefundable = (SELECT property_cancellation_policy_setup.is_nonrefundable FROM property_cancellation_policy_setup WHERE property_cancellation_policy_setup.cancellation_policy_id = property_cancellation_policy.id),
property_cancellation_policy.is_free_cancellation = (SELECT property_cancellation_policy_setup.is_free_cancellation FROM property_cancellation_policy_setup WHERE property_cancellation_policy_setup.cancellation_policy_id = property_cancellation_policy.id),
property_cancellation_policy.type = (SELECT property_cancellation_policy_setup.type FROM property_cancellation_policy_setup WHERE property_cancellation_policy_setup.cancellation_policy_id = property_cancellation_policy.id),
property_cancellation_policy.`value` = (SELECT property_cancellation_policy_setup.`value` FROM property_cancellation_policy_setup WHERE property_cancellation_policy_setup.cancellation_policy_id = property_cancellation_policy.id)

        ") ;


        DB::statement("DROP TABLE IF EXISTS property_cancellation_policy_setup");

    }


}
