<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (!Schema::hasTable('vendor_orders')) {
            return;
        }

        Schema::table('vendor_orders', function (Blueprint $table) {
            if (!Schema::hasColumn('vendor_orders', 'admin_action_note')) {
                $table->text('admin_action_note')->nullable()->after('cancellation_response');
            }
            if (!Schema::hasColumn('vendor_orders', 'admin_action_at')) {
                $table->timestamp('admin_action_at')->nullable()->after('admin_action_note');
            }
        });
    }

    public function down(): void
    {
        if (!Schema::hasTable('vendor_orders')) {
            return;
        }

        Schema::table('vendor_orders', function (Blueprint $table) {
            if (Schema::hasColumn('vendor_orders', 'admin_action_at')) {
                $table->dropColumn('admin_action_at');
            }
            if (Schema::hasColumn('vendor_orders', 'admin_action_note')) {
                $table->dropColumn('admin_action_note');
            }
        });
    }
};
