<?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_permohonan', function (Blueprint $table) {
            $table->id();

            // Data Pemohon
            $table->string('nama_lengkap')->nullable()->comment('Nama lengkap pemohon');
            $table->string('nik')->nullable()->unique()->comment('Nomor Induk Kependudukan pemohon');
            $table->string('tempat_lahir')->nullable()->comment('Tempat lahir pemohon');
            $table->date('tanggal_lahir')->nullable()->comment('Tanggal lahir pemohon');
            $table->string('jenis_kelamin')->nullable()->comment('Jenis kelamin pemohon');
            $table->string('agama')->nullable()->comment('Agama pemohon');
            $table->string('pekerjaan')->nullable()->comment('Pekerjaan pemohon');
            $table->text('alamat')->nullable()->comment('Alamat lengkap sesuai KTP');

            // Detail Permohonan
            $table->text('maksud_permohonan')->nullable()->comment('Maksud atau isi permohonan');
            $table->string('tujuan_permohonan')->nullable()->comment('Tujuan permohonan diajukan');

            // Informasi Surat
            $table->string('nomor_surat')->unique()->nullable()->comment('Nomor surat permohonan');
            $table->date('tanggal_dikeluarkan')->nullable()->comment('Tanggal surat dikeluarkan');

            // Status Persetujuan
            $table->enum('status', ['menunggu_acc_admin_desa', 'disetujui', 'ditolak'])->default('menunggu_acc_admin_desa');
            $table->string('file_path')->nullable()->comment('Path file PDF surat yang sudah disetujui');
            $table->text('catatan_penolakan')->nullable()->comment('Catatan jika surat ditolak');
            $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_permohonan');
    }
};