<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Menambahkan field is_primary dan sort_order untuk
     * menandai lokasi pilihan utama (contoh: Pusdiklat)
     */
    public function up(): void
    {
        Schema::table('business_trip_locations', function (Blueprint $table) {
            if (!Schema::hasColumn('business_trip_locations', 'is_primary')) {
                // Add after is_active if exists, otherwise at the end
                if (Schema::hasColumn('business_trip_locations', 'is_active')) {
                    $table->boolean('is_primary')->default(false)->after('is_active');
                } else {
                    $table->boolean('is_primary')->default(false);
                }
            }
            if (!Schema::hasColumn('business_trip_locations', 'sort_order')) {
                $table->integer('sort_order')->default(0);
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('business_trip_locations', function (Blueprint $table) {
            $table->dropColumn(['is_primary', 'sort_order']);
        });
    }
};
