<?php

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

/**
 * medreg_tenant_setups — the chosen business type per tenant. Deliberately a
 * satellite table: the core `business` table is NEVER altered (module-only
 * rule / Ground Rule 1). One row per business.
 */
return new class extends Migration {
    public function up(): void
    {
        if (! Schema::hasTable('medreg_tenant_setups')) {
            Schema::create('medreg_tenant_setups', function (Blueprint $t) {
                $t->bigIncrements('id');
                $t->unsignedInteger('business_id')->unique(); // ERP business.id (plain column)
                $t->string('business_type_key', 60);          // medreg_business_types.type_key
                $t->json('selected_modules')->nullable();     // final spec_key list the wizard applied
                $t->timestamp('wizard_completed_at')->nullable();
                $t->unsignedInteger('completed_by')->nullable(); // users.id (plain column)
                $t->timestamps();
            });
        }
    }

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