<?php

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

class CreatePrPurchaseChangesTable extends Migration
{
    public function up()
    {
        Schema::dropIfExists('pr_purchase_changes');
        Schema::create('pr_purchase_changes', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('pr_purchase_share_id');
            $table->unsignedInteger('purchase_line_id');
            $table->decimal('original_qty', 8, 2);
            $table->decimal('original_price', 15, 4);
            $table->decimal('requested_qty', 8, 2);
            $table->decimal('requested_price', 15, 4);
            $table->text('supplier_note')->nullable();
            $table->enum('status', ['pending', 'approved', 'rejected'])->default('pending');
            $table->text('admin_note')->nullable();
            $table->timestamps();

            $table->foreign('pr_purchase_share_id')
                  ->references('id')->on('pr_purchase_shares')
                  ->onDelete('cascade');

            $table->foreign('purchase_line_id')
                  ->references('id')->on('purchase_lines')
                  ->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('pr_purchase_changes');
    }
}
