<?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('voters', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignUuid('desa_id')->constrained('desa')->cascadeOnDelete();
            $table->string('nama');
            $table->text('nik_encrypted');
            $table->char('nik_hash', 64);
            $table->string('tps');
            $table->string('rt')->nullable();
            $table->string('rw')->nullable();
            $table->enum('status_terdaftar', ['terdaftar', 'tidak_terdaftar', 'pindah'])->default('terdaftar');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['desa_id', 'nama']);
            $table->index(['desa_id', 'nik_hash']);
        });
    }

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