// database/migrations/xxxx_xx_xx_xxxxxx_create_surat_kelahirans_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_kelahiran', function (Blueprint $table) {
            $table->id();
            $table->foreignId('penduduk_id')->constrained('penduduk')->cascadeOnDelete(); // Bayi yang lahir
            $table->foreignId('ayah_id')->nullable()->constrained('penduduk')->nullOnDelete(); // Ayah
            $table->foreignId('ibu_id')->nullable()->constrained('penduduk')->nullOnDelete(); // Ibu

            $table->string('nomor_surat')->unique()->nullable(); // Akan diisi saat disetujui
            $table->date('tanggal_lahir_bayi');
            $table->string('tempat_lahir_bayi');
            $table->string('nama_bayi');
            $table->enum('jenis_kelamin_bayi', ['Laki-laki', 'Perempuan']);
            $table->float('berat_bayi_kg')->nullable();
            $table->float('panjang_bayi_cm')->nullable();
            $table->string('anak_ke')->nullable(); // Anak ke-berapa

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

            // Untuk persetujuan
            $table->enum('status', ['menunggu_acc_admin_desa', 'disetujui', 'ditolak'])->default('menunggu_acc_admin_desa');
            $table->string('file_path')->nullable(); // Path ke PDF surat
            $table->text('catatan_penolakan')->nullable(); // Alasan jika ditolak
            $table->foreignId('disetujui_oleh')->nullable()->constrained('users')->nullOnDelete(); // Admin desa yang menyetujui
            $table->timestamp('tanggal_disetujui')->nullable();

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

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