<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('good_received_notes', function (Blueprint $table) {
            // Audit fields for cancellation
            $table->foreignId('cancelled_by')->nullable()->constrained('contacts')->onDelete('restrict')->after('notes');
            $table->text('cancelled_reason')->nullable()->after('cancelled_by');
            $table->dateTime('cancelled_at')->nullable()->after('cancelled_reason');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('good_received_notes', function (Blueprint $table) {
            $table->dropForeign(['cancelled_by']);
            $table->dropColumn(['cancelled_by', 'cancelled_reason', 'cancelled_at']);
        });
    }
};
