<?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
    {
        // Drop the existing table if it exists to recreate it with the new schema
        Schema::dropIfExists('surat_kematian');

        Schema::create('surat_kematian', function (Blueprint $table) {
            $table->id();

            // Informasi Almarhum/Almarhumah (Manual Static Input)
            $table->string('nama_lengkap_almarhum')->nullable();
            $table->string('nik_almarhum')->nullable();
            $table->string('tempat_lahir_almarhum')->nullable();
            $table->date('tanggal_lahir_almarhum')->nullable();
            $table->string('jenis_kelamin_almarhum')->nullable();
            $table->text('alamat_almarhum')->nullable();
            $table->string('agama_almarhum')->nullable();
            $table->string('pekerjaan_almarhum')->nullable();

            // Informasi Kematian
            $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();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('surat_kematian');
    }
};