<?php

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

/**
 * VRC repair-specific settings store (key/value per business, JSON values).
 *
 * All VRC tables are prefixed vrc_ and scoped by business_id. References into
 * ERP core tables (contacts, products, transactions, business_locations,
 * users) are plain indexed columns — no cross-table FK constraints — matching
 * the existing module convention (see Modules\Bms migrations).
 */
return new class extends Migration {
    public function up(): void
    {
        if (! Schema::hasTable('vrc_settings')) {
            Schema::create('vrc_settings', function (Blueprint $t) {
                $t->bigIncrements('id');
                $t->unsignedInteger('business_id');
                $t->string('key', 191);
                $t->longText('value')->nullable();
                $t->timestamps();
                $t->unique(['business_id', 'key']);
            });
        }
    }

    public function down(): void
    {
        Schema::dropIfExists('vrc_settings');
    }
};
