<?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
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->foreignId('assigned_to')->nullable()->after('user_id')->constrained('users')->nullOnDelete();
            $table->timestamp('claimed_at')->nullable()->after('assigned_to');
            $table->timestamp('failed_at')->nullable()->after('completed_at');
            $table->timestamp('info_requested_at')->nullable()->after('failed_at');
            $table->string('failure_reason')->nullable()->after('info_requested_at');
            $table->text('fulfillment_note')->nullable()->after('failure_reason');
        });
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropConstrainedForeignId('assigned_to');
            $table->dropColumn([
                'claimed_at',
                'failed_at',
                'info_requested_at',
                'failure_reason',
                'fulfillment_note',
            ]);
        });
    }
};
