<?php

use Illuminate\Database\Migrations\Migration;
use App\Models\Settings;

class AddPanelsModuleToggle extends Migration
{
    public function up()
    {
        $settings = Settings::find(1);
        if (!$settings) {
            return;
        }

        $modules = $settings->modules ?? [];
        if (!array_key_exists('panels', $modules)) {
            $modules['panels'] = true;
            $settings->modules = $modules;
            $settings->save();
        }
    }

    public function down()
    {
        $settings = Settings::find(1);
        if (!$settings) {
            return;
        }

        $modules = $settings->modules ?? [];
        unset($modules['panels']);
        $settings->modules = $modules;
        $settings->save();
    }
}
