<?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
    {
        // Update home_features table
        Schema::table('home_features', function (Blueprint $table) {
            $table->enum('icon_type', ['emoji', 'image'])->default('emoji')->after('icon');
            $table->string('icon_image')->nullable()->after('icon_type');
        });

        // Update menu_items table
        Schema::table('menu_items', function (Blueprint $table) {
            $table->enum('icon_type', ['emoji', 'image'])->default('emoji')->after('icon');
            $table->string('icon_image')->nullable()->after('icon_type');
        });

        // Update brand_showcases table if icon column exists
        if (Schema::hasColumn('brand_showcases', 'icon')) {
            Schema::table('brand_showcases', function (Blueprint $table) {
                $table->enum('icon_type', ['emoji', 'image'])->default('emoji')->after('icon');
                $table->string('icon_image')->nullable()->after('icon_type');
            });
        }
    }

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

        Schema::table('menu_items', function (Blueprint $table) {
            $table->dropColumn(['icon_type', 'icon_image']);
        });

        if (Schema::hasColumn('brand_showcases', 'icon_type')) {
            Schema::table('brand_showcases', function (Blueprint $table) {
                $table->dropColumn(['icon_type', 'icon_image']);
            });
        }
    }
};
