<?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('TerakhirTerbit', function (Blueprint $table) {
            $table->id('TerakhirTerbitID');
            $table->string('Kategori_ID'); // pertek, amdal, dll (identifier string)
            $table->string('NamaIzin'); // nama izin dari API
            $table->string('Pemohon'); // nama pemohon dari API
            $table->date('TanggalTerbit'); // tanggal terbit dari API
            $table->dateTime('ApiLastUpdated'); // from API last_updated field
            $table->date('SyncDate'); // date when this data was synced
            $table->timestamps();

            // Index untuk performa
            $table->index(['Kategori_ID', 'TanggalTerbit']);
            $table->index(['Kategori_ID', 'SyncDate']);
        });
    }

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