<?php

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

class CreatePricesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('prices', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('product_id');
            $table->decimal('sap_price', 15, 2);
            $table->smallInteger('sap_price_type');
            $table->decimal('sap_price_prev', 15, 2)->nullable();
            $table->decimal('sap_disc_perc', 6, 2)->nullable();
            $table->date('sap_disc_start')->nullable();
            $table->date('sap_disc_end')->nullable();
            $table->string('sap_avail', 1);
            $table->smallInteger('sap_lead_time')->nullable();
            $table->decimal('sap_quant', 15, 2)->nullable();
            $table->string('sync_hash')->nullable();
            $table->dateTime('last_sync_at')->nullable();
            $table->boolean('to_sync')->default(true);
            $table->timestamps();

            $table->foreign('product_id')
                ->references('id')->on('products')
                ->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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