<?php

declare(strict_types=1);

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

return new class extends Migration
{
    /**
     * Maestro targets one deployed instance per database: no multi-tenant row on users/customers.
     * The organizations table remains a singleton company profile (Settings › Organization).
     */
    public function up(): void
    {
        if (Schema::hasTable('customers') && Schema::hasColumn('customers', 'organization_id')) {
            Schema::table('customers', function (Blueprint $table) {
                $table->dropConstrainedForeignId('organization_id');
            });
        }

        if (Schema::hasTable('users') && Schema::hasColumn('users', 'organization_id')) {
            Schema::table('users', function (Blueprint $table) {
                $table->dropConstrainedForeignId('organization_id');
            });
        }
    }

    public function down(): void
    {
        // Non-reversible data migration for typical installs; avoid re-adding NOT NULL FKs over live rows.
    }
};
