<?php

declare(strict_types=1);

namespace Plugin\css_vatSelect\src\cssPlugin;

use JTL\Shop;
use JTL\Cron\Job;
use JTL\Cron\JobInterface;
use JTL\Cron\QueueEntry;
use JTL\Plugin\Helper as PluginHelper;

/**
 * Class CronJob
 */
class CronJob extends Job {

	public function start(QueueEntry $queueEntry): JobInterface {
		parent::start($queueEntry);

		$db = Shop::Container()->getDB();
		$oPlugin = $db->select("tplugin", ['cPluginID', 'nStatus'], ['css_VatSelect', '2']);
		if (!empty($oPlugin) && $oPlugin !== false) {
			$loader = PluginHelper::getLoaderByPluginID((int)$oPlugin->kPlugin, Shop::Container()->getDB(), Shop::Container()->getCache());
			$oPlugin = $loader->init((int)$oPlugin->kPlugin);
			$oCssPlugin = cssPlugin::getInstance($oPlugin);
			if ($oCssPlugin->getConfig()->pluginActive == 'Y') {
				$result = $oCssPlugin->getGeoIP(false);
			}
		}
		$this->setFinished((bool)$result);
		return $this;
	}


}