<?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('terakhir_terbit', function (Blueprint $table) {
            $table->id();
            $table->string('kategori'); // pertek, amdal, etc
            $table->string('nama_izin'); // nama izin dari API
            $table->string('pemohon'); // nama pemohon dari API
            $table->date('tanggal_terbit'); // tanggal terbit dari 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
            $table->index(['kategori', 'tanggal_terbit']);
            $table->index(['kategori', 'sync_date']);
        });
    }

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