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

            // Data Pemohon (yang membutuhkan surat domisili)
            $table->string('nama_lengkap')->nullable()->comment('Nama lengkap pemohon');
            $table->string('nik')->nullable()->unique()->comment('Nomor Induk Kependudukan pemohon');
            $table->string('nomor_kartu_keluarga')->nullable()->comment('Nomor Kartu Keluarga 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('status_perkawinan')->nullable()->comment('Status perkawinan pemohon');
            $table->string('pekerjaan')->nullable()->comment('Pekerjaan pemohon');
            $table->text('alamat_saat_ini')->nullable()->comment('Alamat pemohon saat ini');
            $table->string('rt')->nullable()->comment('RT alamat pemohon');
            $table->string('rw')->nullable()->comment('RW alamat pemohon');

            // Dokumen Pendukung
            $table->string('foto_ktp_path')->nullable()->comment('Path foto KTP pemohon');
            $table->string('foto_kartu_keluarga_path')->nullable()->comment('Path foto Kartu Keluarga pemohon');

            // Informasi Surat
            $table->text('keperluan')->nullable()->comment('Keperluan pembuatan surat keterangan domisili');
            $table->string('nomor_surat')->unique()->nullable()->comment('Nomor surat keterangan domisili');
            $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_keterangan_domisili');
    }
};