<?php

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

/**
 * A per-order tracking token powers the public, no-login repair-status tracker
 * in the customer portal (spec §6.13).
 */
return new class extends Migration {
    public function up(): void
    {
        if (Schema::hasTable('vrc_repair_orders') && ! Schema::hasColumn('vrc_repair_orders', 'tracking_token')) {
            Schema::table('vrc_repair_orders', function (Blueprint $t) {
                $t->string('tracking_token', 64)->nullable()->unique()->after('number');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasColumn('vrc_repair_orders', 'tracking_token')) {
            Schema::table('vrc_repair_orders', function (Blueprint $t) {
                $t->dropColumn('tracking_token');
            });
        }
    }
};
