<?php

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

/**
 * Make package items presentable + customizable: bilingual name, a grouping
 * category, an optional flag (client may drop optional items) and ordering.
 * Powers the "what's included" list in the client funnel and the upcoming
 * package customization step.
 */
return new class extends Migration {
    public function up(): void
    {
        Schema::table('bms_package_items', function (Blueprint $t) {
            if (! Schema::hasColumn('bms_package_items', 'name_ar')) {
                $t->string('name_ar', 191)->nullable()->after('name');
            }
            if (! Schema::hasColumn('bms_package_items', 'category')) {
                $t->string('category', 40)->nullable()->after('name_ar');
            }
            if (! Schema::hasColumn('bms_package_items', 'is_optional')) {
                $t->boolean('is_optional')->default(false)->after('quantity');
            }
            if (! Schema::hasColumn('bms_package_items', 'sort_order')) {
                $t->unsignedInteger('sort_order')->default(0)->after('is_optional');
            }
        });
    }

    public function down(): void
    {
        Schema::table('bms_package_items', function (Blueprint $t) {
            foreach (['name_ar', 'category', 'is_optional', 'sort_order'] as $c) {
                if (Schema::hasColumn('bms_package_items', $c)) {
                    $t->dropColumn($c);
                }
            }
        });
    }
};
