<?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
    {
        Schema::table('tenants', function (Blueprint $table): void {
            $table->string('lifecycle_state', 32)->default('active')->after('is_active');
            $table->string('locale', 12)->nullable()->after('lifecycle_state');
            $table->string('timezone', 64)->nullable()->after('locale');
            $table->json('company_profile')->nullable()->after('timezone');
            $table->json('onboarding_progress')->nullable()->after('company_profile');
            $table->timestamp('onboarding_completed_at')->nullable()->after('onboarding_progress');
            $table->index('lifecycle_state');
        });
    }

    public function down(): void
    {
        Schema::table('tenants', function (Blueprint $table): void {
            $table->dropIndex(['lifecycle_state']);
            $table->dropColumn([
                'lifecycle_state',
                'locale',
                'timezone',
                'company_profile',
                'onboarding_progress',
                'onboarding_completed_at',
            ]);
        });
    }
};
