<?php

namespace KupShop\PohodaBundle\Tests;

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\PohodaBundle\Utils\PohodaConnector;

/**
 * Trait TestUtilHelper.
 */
trait TestUtilHelper
{
    public function prepareMServer($username = 'Admin', $passwd = '', $ico = '0123456789', $url = 'http://test:4052/xml')
    {
        $this->pohodaConnector = ServiceContainer::getService(PohodaConnector::class);
        $dbcfg = \Settings::getDefault();

        if (empty($dbcfg->loadValue('pohoda'))) {
            \Settings::getDefault()->saveValue('pohoda', []);
        }

        $pohoda = $dbcfg->loadValue('pohoda') ?: [];

        $pohoda['mservers'][] = [
            'active' => 'Y',
            'url' => $url,
            'username' => $username,
            'password' => $passwd,
            'server_name' => '123',
            'ico' => $ico,
            'maintenanceFrom' => '',
            'maintenanceTo' => '',
            'productsIn' => [
                'last_sync' => '13.5.2021 16:12:59',
                'internet' => 'N', ],
            'ordersOut' => [
                'last_sync' => '13.5.2021 17:28:09',
                'last_sync_diff' => '', ],
            'issuedInvoiceIn' => [
                'last_sync' => '',
                'last_sync_diff' => '', ],
            'dev_activate' => 'Y',
            'usersOut' => [
                'last_sync' => '13.5.2021 17:28:09',
                'last_sync_diff' => '', ],
        ];

        $dbcfg->updateValue('pohoda', $pohoda);
        $this->pohodaConnector->reloadConfig();
    }
}
