<?php

declare(strict_types=1);

namespace External\PompoBundle\Resources\script;

use External\PompoBundle\DataGo\Synchronizer\ProductSynchronizer;
use External\PompoBundle\Util\PompoUtil;
use KupShop\AdminBundle\Util\Script\Script;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;

class DataGoProductSynchronizationScript extends Script
{
    protected static $name = '[DataGo] Run products synchronization';
    protected static $defaultParameters = [
        'type' => ProductSynchronizer::PROCESS_TYPE_FULL_UPDATE,
    ];

    protected function run(array $arguments)
    {
        sqlGetConnection()->getConfiguration()->setSQLLogger();

        if (!($arguments['type'] ?? false)) {
            $this->log('You must specify process type!');

            return;
        }

        $pompoUtil = ServiceContainer::getService(PompoUtil::class);

        $this->log('Running...');

        $pompoUtil->synchronizeDataGoProducts([$arguments['type']]);

        $this->log('Done');
    }
}

return DataGoProductSynchronizationScript::class;
