<?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('surats', function (Blueprint $table) {
            $table->id();
            $table->string('nomor_surat')->unique();
            $table->enum('jenis_surat', [
                'Pengantar KTP',
                'Pengantar KK',
                'Keterangan Domisili',
                'Keterangan Usaha',
                'Keterangan Tidak Mampu',
                'Keterangan Kelahiran',
                'Keterangan Kematian',
                'Lainnya'
            ]);
            $table->foreignId('warga_id')->constrained('wargas')->onDelete('restrict');
            $table->date('tanggal_surat');
            $table->text('keperluan');
            $table->text('keterangan')->nullable();
            $table->enum('status', ['Pending', 'Disetujui', 'Ditolak'])->default('Pending');
            $table->string('file_surat')->nullable();
            $table->foreignId('user_id')->constrained('users')->onDelete('restrict');
            $table->timestamps();
            $table->softDeletes();
            
            $table->index(['warga_id', 'status']);
            $table->index('tanggal_surat');
        });
    }

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