// database/migrations/xxxx_xx_xx_xxxxxx_create_surat_pendatangs_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_pendatang', function (Blueprint $table) {
            $table->id();
            $table->foreignId('penduduk_id')->constrained('penduduk')->cascadeOnDelete(); // Penduduk yang datang

            $table->string('nomor_surat')->unique()->nullable();
            $table->string('alamat_asal');
            $table->string('rt_asal')->nullable();
            $table->string('rw_asal')->nullable();
            $table->string('dusun_asal')->nullable();
            $table->string('desa_asal');
            $table->string('kecamatan_asal');
            $table->string('kabupaten_asal');
            $table->string('provinsi_asal');
            $table->date('tanggal_datang');
            $table->text('maksud_tujuan');

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

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