<?php

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

return new class extends Migration
{
    /**
     * Tambah kolom email ke tabel users dan pengajuan_masjid.
     * Sebelumnya, kolom 'username' dipakai sekaligus sebagai email login.
     * Sekarang dipisah: 'username' = nama pengguna bebas, 'email' = alamat email unik untuk login.
     */
    public function up(): void
    {
        // Tambah kolom email ke tabel users
        Schema::table('users', function (Blueprint $table) {
            // Diletakkan setelah 'username', nullable agar data lama tidak error
            $table->string('email')->nullable()->unique()->after('username');
        });

        // Tambah kolom email ke tabel pengajuan_masjid
        Schema::table('pengajuan_masjid', function (Blueprint $table) {
            $table->string('email')->nullable()->after('username');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('email');
        });

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