<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            // gender
            DB::statement("
                DO $$ BEGIN
                    CREATE TYPE user_gender_enum AS ENUM (
                        'Lelaki',
                        'Perempuan'
                    );
                EXCEPTION
                    WHEN duplicate_object THEN null;
                END $$;
            ");
            DB::statement("
                ALTER TABLE users
                ADD COLUMN IF NOT EXISTS gender user_gender_enum
                DEFAULT NULL
            ");
            // marriage status
            $table->string('marriage_status')->nullable() ->comment('Belum Berkahwin, Berkahwin, Bercerai, Balu, Duda');
            $table->integer('member_number')->nullable();
            $table->string('member_type')->nullable() ->comment('Anggota, Pesara');
            // join date
            $table->date('join_date')->nullable();
            // birth date
            $table->date('birth_date')->nullable();
            // birth place
            $table->string('birth_place')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('gender');
            $table->dropColumn('marriage_status');
            $table->dropColumn('member_number');
            $table->dropColumn('member_type');
            $table->dropColumn('join_date');
            $table->dropColumn('birth_date');
            $table->dropColumn('birth_place');
        });

        DB::statement("DROP TYPE IF EXISTS user_gender_enum");
    }
};
