<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use App\Providers\AppServiceProvider;
use Src\Modules\JsonObjects\Interfaces\IFactory;

return new class extends Migration {

    /**
     * Run the migrations.
     */
    public function up(): void
    {
        /** @var IFactory */
        $factory = app(AppServiceProvider::ADMIN_MODULES)->getJsonObjectsFactory();
        $item = $factory->getDtoFactory()->getItemFactory()->createPersist(\Modules\Objects\MainInfo::TYPE);
        $item->load(['key' => 'main_info', 'name' => 'Main info', 'disabled' => 1]);

        $attrs = $item->getInsertAttrs();
        DB::table('json_items')->insert($attrs);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('json_items')->where('key', '=', 'main_info')->delete();
    }
};
