<?php

use auctionforge\inc\Debug;
use auctionforge\inc\helpers\LotHelper;
use auctionforge\inc\import\AuctionList;
use auctionforge\inc\import\LotList;
use auctionforge\inc\import\SilentMigrator;
use auctionforge\inc\model\Auction;

if (!empty($_SERVER['DOCUMENT_ROOT'])) {
    die("Access denied");
}

define('CRON_TASKS_BASE_PATH', __DIR__);
define('WP_USE_THEMES', false);
require(CRON_TASKS_BASE_PATH . '/../../../../wp-load.php');

if (!is_plugin_active(basename(dirname(__DIR__)) . '/' . basename(dirname(__DIR__)) . '.php')) {
    die("Plugin AuctionForge disabled\r\n");
}

if (LotHelper::startSync(AUCTIONFORGE_SYNC_ARCHIVE_START, 360) || WP_DEBUG) {
    Debug::logData(
        array(
            "info" => "Start \"Past auction\" process",
            "is_debug_enable" => WP_DEBUG
        )
    );
//    $migrator = new SilentMigrator();
//    $migrator->run();

    $auctionList = new AuctionList();
    $auctionList->init();
    if (!empty($auctionList->getErrors())) {
        $errors = $auctionList->getErrors();
        var_dump($errors);
        Debug::logData($errors, "auction-list");
    }

    $lotList = new LotList();
    $lotList->setPriority(5);
    $lotList->init(false);
    if (!empty($lotList->getErrors())) {
        $errors = $lotList->getErrors();
        var_dump($errors);
        Debug::logData($errors, "lot-list-old");
    }

    update_option(AUCTIONFORGE_SYNC_ARCHIVE_START, "0", 'no');

    $logData["info"] = "\"Past auction\" process is finished";
    if (!empty($auctionList->getLoggedInfo())) {
        $logData["auctions"] = $auctionList->getLoggedInfo();
    }
    if (!empty($lotList->getLoggedInfo())) {
        $logData["lots"] = $lotList->getLoggedInfo();
    }
    Debug::logData($logData);
}
