<?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_pengantar_sktm', function (Blueprint $table) {
            $table->id();
            $table->foreignId('penduduk_id')->constrained('penduduk')->cascadeOnDelete(); // Pemohon SKTM

            $table->string('nomor_surat')->unique()->nullable();
            $table->text('perihal');
            $table->string('tujuan_pengantar'); // Misal: Dinas Sosial, Rumah Sakit, Sekolah, dll.
            $table->date('tanggal_pengajuan');

            $table->enum('status', ['menunggu_acc_rt_rw', 'menunggu_acc_admin_desa', 'disetujui', 'ditolak'])->default('menunggu_acc_rt_rw');
            $table->string('file_path')->nullable();
            $table->text('catatan_penolakan')->nullable();

            $table->foreignId('disetujui_oleh_rt_rw')->nullable()->constrained('users')->nullOnDelete(); // User RT/RW
            $table->timestamp('tanggal_disetujui_rt_rw')->nullable();

            $table->foreignId('disetujui_oleh_admin_desa')->nullable()->constrained('users')->nullOnDelete(); // User Admin Desa
            $table->timestamp('tanggal_disetujui_admin_desa')->nullable();

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

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