<?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('anggotas', function (Blueprint $table) {
            // Rename nim → no_identitas (lebih general: NIM/NISN/NIP)
            $table->renameColumn('nim', 'no_identitas');
        });

        Schema::table('anggotas', function (Blueprint $table) {
            // Kolom baru untuk keamanan & akuntabilitas
            $table->string('jenis_anggota')->after('no_identitas');          // Mahasiswa, Siswa, Dosen, Umum
            $table->string('no_ktp', 20)->after('jenis_anggota');            // NIK 16 digit
            $table->text('alamat')->after('no_hp');                          // Alamat lengkap
            $table->string('nama_wali')->after('alamat');                    // Nama penjamin
            $table->string('no_hp_wali', 20)->after('nama_wali');            // No HP penjamin
            $table->string('hubungan_wali')->after('no_hp_wali');            // Orang Tua / Saudara / dll

            // Prodi jadi nullable (umum/dosen mungkin tidak punya prodi)
            $table->string('prodi')->nullable()->change();
        });
    }

    public function down(): void
    {
        Schema::table('anggotas', function (Blueprint $table) {
            $table->dropColumn([
                'jenis_anggota', 'no_ktp', 'alamat',
                'nama_wali', 'no_hp_wali', 'hubungan_wali',
            ]);
            $table->string('prodi')->nullable(false)->change();
        });

        Schema::table('anggotas', function (Blueprint $table) {
            $table->renameColumn('no_identitas', 'nim');
        });
    }
};
