<?php

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

class CreatePackageTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('packages', function (Blueprint $table) {
            $table->id();
            $table->string('image', 250)->nullable();
            $table->string('video', 300)->nullable();
            $table->enum('video_type', [1,2])->nullable()->comment('1-> Youtube video file, 2-> localfile');

            $table->unsignedBigInteger('package_category_id')->nullable();
            $table->unsignedBigInteger('user_id')->nullable();
            $table->bigInteger('visit_counts')->nullable();

            // for packages, to include the price, flight duration, and journey start and end date, and other options
            $table->json('meta')->nullable();
            $table->boolean('offer')->virtualAs('meta->"$.offer"')->index();

            $table->foreign('package_category_id')->references('id')->on('package_categories')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('user_id')->references('id')->on('users');

            $table->index(['user_id', 'package_category_id']);

            $table->softDeletes();
            $table->timestamps();

            // Set engine to InnoDB it's useful in join and constraint
            $table->engine = 'InnoDB';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('package');
    }
}
