<?php

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

class CreateVendorQuotesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('vendor_quotes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('lead_id')->constrained('leads')->cascadeOnDelete();
            $table->string('vendor_name');
            $table->decimal('vendor_raw_cost', 12, 2);
            $table->decimal('our_markup_percent', 5, 2);
            $table->decimal('client_final_price', 12, 2)->storedAs('ROUND(vendor_raw_cost * (1 + (our_markup_percent / 100)), 2)');
            $table->boolean('selection_toggle')->default(false);
            $table->timestamps();

            $table->index(['lead_id', 'selection_toggle']);
        });
    }

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