<?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('contacts', function (Blueprint $table) {
            $table->string('whatsapp')->after('nama')->nullable();
        });

        // Salin data email ke kolom whatsapp (jika ada)
        DB::table('contacts')->whereNotNull('email')->update([
            'whatsapp' => DB::raw('email'),
        ]);

        Schema::table('contacts', function (Blueprint $table) {
            $table->dropColumn('email');
        });
    }

    public function down(): void
    {
        Schema::table('contacts', function (Blueprint $table) {
            $table->string('email')->after('nama')->nullable();
        });

        DB::table('contacts')->whereNotNull('whatsapp')->update([
            'email' => DB::raw('whatsapp'),
        ]);

        Schema::table('contacts', function (Blueprint $table) {
            $table->dropColumn('whatsapp');
        });
    }
};
