<?php

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

class CreateBoxOrderLinesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('box_order_lines', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger("box_order_id");
            $table->unsignedBigInteger("box_product_variant_id")->nullable();
            $table->unsignedBigInteger("user_subscription_id")->nullable();
            $table->double("price",2);
            $table->integer("quantity");
            $table->double("subtotal",2);
            $table->double("vat",2);
            $table->unsignedBigInteger("discount_id")->nullable();
            $table->double("total",2);
            $table->timestamps();

            $table->foreign("box_order_id")->references("id")->on("box_orders")->onDelete("cascade");
            $table->foreign("user_subscription_id")->references("id")->on("user_subscriptions")->onDelete("restrict");
        });
    }

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