<?php

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

/**
 * Phase 1 (§3.1) — annotated body-damage diagram captured at vehicle check-in.
 * Stored as JSON markers ([{x,y,type,note}, …] in % coordinates over a body
 * outline) on the intake inspection.
 */
return new class extends Migration {
    public function up(): void
    {
        if (Schema::hasTable('vrc_inspections') && ! Schema::hasColumn('vrc_inspections', 'body_diagram')) {
            Schema::table('vrc_inspections', function (Blueprint $t) {
                $t->longText('body_diagram')->nullable()->after('summary');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('vrc_inspections') && Schema::hasColumn('vrc_inspections', 'body_diagram')) {
            Schema::table('vrc_inspections', fn (Blueprint $t) => $t->dropColumn('body_diagram'));
        }
    }
};
