<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            if (!Schema::hasColumn('users', 'email_verification_code')) {
                if (!Schema::hasColumn('users', 'email_verification_code')) { $table->string('email_verification_code')->nullable(); }
            }
            if (!Schema::hasColumn('users', 'verification_code_sent_at')) {
                if (!Schema::hasColumn('users', 'verification_code_sent_at')) { $table->timestamp('verification_code_sent_at')->nullable(); }
            }
            if (!Schema::hasColumn('users', 'email_verified_at')) {
                if (!Schema::hasColumn('users', 'email_verified_at')) { $table->timestamp('email_verified_at')->nullable(); }
            }
            if (!Schema::hasColumn('users', 'phone_verified_at')) {
                if (!Schema::hasColumn('users', 'phone_verified_at')) { $table->timestamp('phone_verified_at')->nullable(); }
            }
        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $columns = ['email_verification_code', 'verification_code_sent_at', 'email_verified_at', 'phone_verified_at'];
            foreach ($columns as $column) {
                if (Schema::hasColumn('users', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};

