<?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->unsignedBigInteger('finishing_operator_id')->nullable()->after('operator_id');
            $table->index('finishing_operator_id');
            $table->foreign('finishing_operator_id')->references('id')->on('users')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropForeign(['finishing_operator_id']);
            $table->dropIndex(['finishing_operator_id']);
            $table->dropColumn('finishing_operator_id');
        });
    }
};