<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Ubah kolom type dari ENUM ke VARCHAR agar lebih fleksibel.
     * ENUM menyebabkan 500 error jika ada tipe baru yang belum terdaftar.
     */
    public function up(): void
    {
        // Change ENUM to VARCHAR for flexibility
        DB::statement("ALTER TABLE locations MODIFY COLUMN `type` VARCHAR(50) NOT NULL DEFAULT 'other'");
        DB::statement("ALTER TABLE locations MODIFY COLUMN `category` VARCHAR(50) NOT NULL DEFAULT 'internal'");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Revert to ENUM (only if all values are valid)
        DB::statement("ALTER TABLE locations MODIFY COLUMN `type` ENUM('headquarters','branch','bpkp','pemda','kementerian','lembaga','other') NOT NULL DEFAULT 'other'");
        DB::statement("ALTER TABLE locations MODIFY COLUMN `category` ENUM('internal','external') NOT NULL DEFAULT 'internal'");
    }
};
