<?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('mutasi_wargas', function (Blueprint $table) {
            $table->id();
            $table->foreignId('warga_id')->constrained('wargas')->onDelete('cascade');
            $table->enum('jenis_mutasi', ['Pindah Masuk', 'Pindah Keluar', 'Meninggal', 'Lahir']);
            $table->date('tanggal_mutasi');
            $table->text('alamat_tujuan')->nullable();
            $table->text('keterangan')->nullable();
            $table->string('dokumen_url')->nullable();
            $table->foreignId('user_id')->constrained('users')->onDelete('restrict');
            $table->timestamps();
            
            $table->index(['warga_id', 'jenis_mutasi']);
            $table->index('tanggal_mutasi');
        });
    }

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