<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        if (Schema::hasColumn('calls', 'is_private')) {
            Schema::table('calls', function (Blueprint $table) {
                $table->renameColumn('is_private', 'is_public');
            });
            // Invert existing values: was private (1 = hidden), now public (1 = visible)
            DB::table('calls')->update(['is_public' => DB::raw('NOT is_public')]);
        }
    }

    public function down(): void
    {
        DB::table('calls')->update(['is_public' => DB::raw('NOT is_public')]);
        Schema::table('calls', function (Blueprint $table) {
            $table->renameColumn('is_public', 'is_private');
        });
    }
};
