<?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('certificate_records') || Schema::hasColumn('certificate_records', 'verification_token')) {
            return;
        }

        Schema::table('certificate_records', function (Blueprint $table): void {
            $table->string('verification_token', 64)->nullable()->after('certificate_number');
            $table->unique('verification_token');
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('certificate_records') || ! Schema::hasColumn('certificate_records', 'verification_token')) {
            return;
        }

        Schema::table('certificate_records', function (Blueprint $table): void {
            $table->dropUnique(['verification_token']);
            $table->dropColumn('verification_token');
        });
    }
};
