<?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('perizinan_status', function (Blueprint $table) {
            $table->id();
            $table->string('kategori'); // pertek, amdal, etc
            $table->string('status_id'); // ditolak, selesai, proses, total
            $table->string('label'); // Izin Ditolak, Izin Selesai, etc
            $table->integer('value'); // count value
            $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', 'status_id', 'sync_date']);
            $table->unique(['kategori', 'status_id', 'sync_date']); // prevent duplicate data per day
        });
    }

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