<?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::create('members', function (Blueprint $table) {
            $table->id();
            $table->string('nik', 50)->unique();
            $table->string('no_anggota', 50)->unique();
            $table->string('nama');
            $table->string('tempat_lahir')->nullable();
            $table->date('tanggal_lahir')->nullable();
            $table->enum('jenis_kelamin', ['L', 'P'])->nullable();
            $table->string('email')->nullable();
            $table->string('no_telp', 20)->nullable();
            $table->text('alamat')->nullable();
            $table->string('status', 20)->default('aktif');
            $table->string('unit_kerja')->nullable();
            $table->string('pekerjaan')->nullable();
            $table->string('foto_profil')->nullable();
            $table->decimal('simpanan_pokok', 15, 2)->default(0);
            $table->decimal('simpanan_wajib', 15, 2)->default(0);
            $table->decimal('simpanan_sukarela', 15, 2)->default(0);
            $table->decimal('jumlah_simpanan', 15, 2)->default(0);
            $table->unsignedBigInteger('create_user')->nullable();
            $table->timestamp('create_time')->useCurrent();
            $table->unsignedBigInteger('update_user')->nullable();
            $table->timestamp('update_time')->nullable();

            $table->index(['nik', 'no_anggota']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('members');
    }
};
