<?php

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

/**
 * Package customization + 360° media.
 * - bms_lead_halls.package_items: the client's customized component config
 *   [{item_id, qty, included}] captured from the "what's included" editor.
 * - bms_hall_media.type gains a 360 option for panorama tours.
 */
return new class extends Migration {
    public function up(): void
    {
        if (Schema::hasTable('bms_lead_halls') && ! Schema::hasColumn('bms_lead_halls', 'package_items')) {
            Schema::table('bms_lead_halls', function (Blueprint $t) {
                $t->json('package_items')->nullable()->after('addons');
            });
        }

        DB::statement("ALTER TABLE bms_hall_media MODIFY type ENUM('image','video','360') NOT NULL DEFAULT 'image'");
    }

    public function down(): void
    {
        if (Schema::hasColumn('bms_lead_halls', 'package_items')) {
            Schema::table('bms_lead_halls', function (Blueprint $t) {
                $t->dropColumn('package_items');
            });
        }
        DB::statement("ALTER TABLE bms_hall_media MODIFY type ENUM('image','video') NOT NULL DEFAULT 'image'");
    }
};
