// database/migrations/xxxx_xx_xx_xxxxxx_create_surat_kematians_table.php
<?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('surat_kematian', function (Blueprint $table) {
            $table->id();
            $table->foreignId('penduduk_id')->constrained('penduduk')->cascadeOnDelete(); // Penduduk yang meninggal

            $table->string('nomor_surat')->unique()->nullable();
            $table->date('tanggal_kematian');
            $table->time('waktu_kematian')->nullable();
            $table->string('tempat_kematian')->nullable();
            $table->string('penyebab_kematian')->nullable();
            $table->string('yang_menerangkan')->nullable(); // Dokter/Saksi

            // Data Pelapor
            $table->string('nama_pelapor');
            $table->string('nik_pelapor');
            $table->string('hubungan_pelapor_dengan_almarhum');

            $table->enum('status', ['menunggu_acc_admin_desa', 'disetujui', 'ditolak'])->default('menunggu_acc_admin_desa');
            $table->string('file_path')->nullable();
            $table->text('catatan_penolakan')->nullable();
            $table->foreignId('disetujui_oleh')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamp('tanggal_disetujui')->nullable();

            $table->timestamps();
        });
    }

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