<?php

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

/**
 * Adds the product_list column to site_menu.
 *
 * When set to a category id, the menu item pulls that category's active
 * products in as child links (mirrors the existing category_list column, which
 * pulls in sub-categories). Idempotent so it is safe on installs that may
 * already have run it.
 */
return new class extends Migration
{
    public function up(): void
    {
        if (!Schema::hasTable('site_menu') || Schema::hasColumn('site_menu', 'product_list')) {
            return;
        }

        Schema::table('site_menu', function (Blueprint $table) {
            $table->integer('product_list')->default(0)->after('category_list');
        });
    }

    public function down(): void
    {
        if (Schema::hasTable('site_menu') && Schema::hasColumn('site_menu', 'product_list')) {
            Schema::table('site_menu', function (Blueprint $table) {
                $table->dropColumn('product_list');
            });
        }
    }
};
