<?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('FastestPermohonan', function (Blueprint $table) {
            $table->id('FastestPermohonanID');
            $table->string('Kategori_ID'); // pertek, amdal, etc (identifier string)
            $table->string('Nama'); // nama izin from API
            $table->integer('Total'); // jumlah total izin from API
            $table->string('DurasiPemohon')->nullable(); // durasi rata-rata pemohon from API
            $table->string('DurasiPetugas')->nullable(); // durasi rata-rata petugas from API
            $table->dateTime('ApiLastUpdated'); // from API last_updated field
            $table->date('SyncDate'); // date when this data was synced
            $table->timestamps();

            // Index untuk performa - urutkan berdasarkan durasi dan total
            $table->index(['Kategori_ID', 'SyncDate']);
            $table->index(['Kategori_ID', 'Total']); // untuk sorting fastest
        });
    }

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