<?php

declare(strict_types=1);

namespace KupShop\StoresBundle\Resources\script;

use KupShop\AdminBundle\Util\Script\Script;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\StoresBundle\Utils\StoreWarehouseRecalculate;

class RecalculateStoresFromWarehouseScript extends Script
{
    protected static $name = '[Stores] Přepočítat stores na základě warehouse';

    protected static $defaultParameters = [
        'mainStoreOnly' => false,
        'deleteStoresItems' => false,
    ];

    protected function run(array $arguments)
    {
        sqlGetConnection()->transactional(function () use ($arguments) {
            $storesWarehouseRecalculate = ServiceContainer::getService(StoreWarehouseRecalculate::class);
            $storesWarehouseRecalculate->fixStoreWarehouseErrors($arguments['mainStoreOnly'], $arguments['deleteStoresItems']);
        });
    }
}

return RecalculateStoresFromWarehouseScript::class;
