<?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('PerizinanStatus', function (Blueprint $table) {
            $table->id('PerizinanStatusID');
            $table->string('Kategori_ID'); // pertek, amdal, etc (identifier string)
            $table->string('StatusID'); // ditolak, selesai, proses, total
            $table->string('Label'); // Izin Ditolak, Izin Selesai, etc
            $table->integer('Value'); // count value
            $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', 'StatusID', 'SyncDate']);
            $table->unique(['Kategori_ID', 'StatusID', 'SyncDate']); // prevent duplicate data per day
        });
    }

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