<?php

use App\Models\Catalog\MainCategory;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Marks a main category as application-owned rather than tenant-owned — the
 * same mechanism `roles.is_system` already uses. Today the only such row is
 * "Packaging & Add-ons" ({@see MainCategory::SYSTEM_PACKAGING}),
 * which the POS looks up by its constant sort_code and which must survive any
 * administrator's delete.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('main_categories', function (Blueprint $table) {
            $table->boolean('is_system')->default(false)->after('is_active');
        });
    }

    public function down(): void
    {
        Schema::table('main_categories', function (Blueprint $table) {
            $table->dropColumn('is_system');
        });
    }
};
