<?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('fastest_permohonan', function (Blueprint $table) {
            $table->id();
            $table->string('kategori'); // pertek, amdal, etc
            $table->string('nama'); // nama izin from API
            $table->integer('total'); // jumlah total izin from API
            $table->string('durasi_pemohon')->nullable(); // durasi rata-rata pemohon from API
            $table->string('durasi_petugas')->nullable(); // durasi rata-rata petugas from API
            $table->datetime('api_last_updated'); // from API last_updated field
            $table->date('sync_date'); // date when this data was synced
            $table->timestamps();

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

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