<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        if (!Schema::hasTable('departments') || !Schema::hasColumn('departments', 'is_system')) {
            return;
        }

        DB::table('departments')
            ->whereIn('name', [
                'Executive',
                'Finance',
                'Inventory',
                'Marketing',
                'Operations',
                'Sales',
                'System Administration',
            ])
            ->update(['is_system' => true]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // no-op: keep is_system flags
    }
};

