<?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
    {
        Schema::create('surat_sktm', function (Blueprint $table) {
            $table->id();
            $table->foreignId('penduduk_id')->constrained('penduduk')->cascadeOnDelete(); // Penduduk penerima SKTM
            $table->foreignId('surat_pengantar_sktm_id')->nullable()->constrained('surat_pengantar_sktm')->cascadeOnDelete(); // Terhubung ke surat pengantar SKTM

            $table->string('nomor_surat')->unique()->nullable();
            $table->string('nomor_kartu_keluarga'); // Wajib
            // NIK sudah ada di penduduk_id, tidak perlu lagi di sini kecuali untuk keperluan validasi
            $table->string('penghasilan_per_bulan'); // Bisa string (contoh: "< Rp. 1.000.000" atau "Tidak berpenghasilan")

            $table->string('foto_orang_path')->nullable(); // Optional
            $table->string('foto_rumah_path')->nullable(); // Optional
            $table->string('foto_kartu_keluarga_path')->nullable(); // Wajib
            $table->string('foto_ktp_kartu_pelajar_path')->nullable(); // Optional (pilih salah satu)

            $table->date('tanggal_dikeluarkan');
            $table->text('keperluan'); // Keperluan SKTM

            $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_sktm');
    }
};