<?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('membership_plans', function (Blueprint $table) {
            if (!Schema::hasColumn('membership_plans', 'is_public')) {
                $table->boolean('is_public')->default(true)->after('is_active');
            }
            if (!Schema::hasColumn('membership_plans', 'visible_until')) {
                $table->timestamp('visible_until')->nullable()->after('is_public');
            }
        });

        Schema::table('users', function (Blueprint $table) {
            if (!Schema::hasColumn('users', 'admin_badge')) {
                $table->string('admin_badge', 32)->nullable();
            }
        });
    }

    public function down(): void
    {
        Schema::table('membership_plans', function (Blueprint $table) {
            if (Schema::hasColumn('membership_plans', 'visible_until')) {
                $table->dropColumn('visible_until');
            }
            if (Schema::hasColumn('membership_plans', 'is_public')) {
                $table->dropColumn('is_public');
            }
        });

        Schema::table('users', function (Blueprint $table) {
            if (Schema::hasColumn('users', 'admin_badge')) {
                $table->dropColumn('admin_badge');
            }
        });
    }
};
