<?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::dropIfExists('surat_pendatang'); // Hapus tabel lama jika ada

        Schema::create('surat_pendatang', function (Blueprint $table) {
            $table->id();
            $table->string('nama_pendatang'); // Nama pendatang (static input)
            $table->string('nik_pendatang')->unique(); // NIK pendatang (static input)
            $table->string('tempat_lahir_pendatang')->nullable(); // Tempat lahir (static input)
            $table->date('tanggal_lahir_pendatang')->nullable(); // Tanggal lahir (static input)
            $table->enum('jenis_kelamin_pendatang', ['Laki-laki', 'Perempuan'])->nullable(); // Jenis kelamin (static input)
            $table->string('agama_pendatang')->nullable(); // Agama (static input)
            $table->string('pekerjaan_pendatang')->nullable(); // Pekerjaan (static input)
            $table->string('alamat_saat_ini_pendatang')->nullable(); // Alamat saat ini (static input)
            $table->string('rt_saat_ini_pendatang')->nullable(); // RT saat ini (static input)
            $table->string('rw_saat_ini_pendatang')->nullable(); // RW saat ini (static input)


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

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