<?php

namespace KupShop\PohodaBundle\Resources\script;

use KupShop\AdminBundle\Util\Script\Script;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\PohodaBundle\Utils\Importers\UsersImporter;
use KupShop\PohodaBundle\Utils\Tools\TransformHelper;

class PohodaUsersPairScript extends Script
{
    protected static $defaultParameters = [
        'pathToFile' => 'data/files/pohodaUsersIn_response.xml',
    ];

    protected $xslt = 'usersIn.xsl';

    /**
     * @var UsersImporter
     */
    protected $usersImporter;

    /**
     * @var TransformHelper
     */
    protected $transformHelper;

    protected static $name = '[Pohoda] Napárovat uživatele z Pohody na základě emailů';

    public function __construct()
    {
        $this->usersImporter = ServiceContainer::getService(UsersImporter::class);
        $this->transformHelper = ServiceContainer::getService(TransformHelper::class);
    }

    protected function run(array $arguments)
    {
        $this->usersImporter->setFullSync(true);

        if ($arguments['pathToFile']) {
            $XMLStringResponse = file_get_contents($arguments['pathToFile']);
        } else {
            $XMLStringResponse = $this->usersImporter->getData();
        }
        $this->usersImporter->processData($XMLStringResponse);
    }
}

return PohodaUsersPairScript::class;
