<?php

namespace DetailTask;

use LogHelper;
use PpjClient;

/**
 * @property PpjClient $client
 */
class PpjTask extends AbstractTask {
    #region Attributes
    public const TYPE_DAILY = "daily";
    #endregion

    #region Main
    public function init() {
        $this->client = new PpjClient($this->config["ppj_prop"]);
        $this->client->setLogger($this->logger);
    }

    /**
     * @param $type
     * @return void
     * Log disimpan ke table log_ppj_errors
     */
    public function processPpj($type) {
        $this->init();
        if ($type == self::TYPE_DAILY) {
            $this->processPpjDaily();
        } else {
            $this->processPpjMonthly($type);
        }
    }

    private function processPpjDaily() {
        $startTime = microtime(true);
        $this->client->updateDaily();
        $endTime = microtime(true);
        LogHelper::logInfo("Process PPJ Daily", $startTime, $endTime, [], self::LOG_TYPE, $this->logger);
    }

    private function processPpjMonthly($period) {
        $startTime = microtime(true);
        $this->client->updateMonthly($period);
        $endTime = microtime(true);
        LogHelper::logInfo("Process PPJ Monthly " . $period, $startTime, $endTime, [], self::LOG_TYPE, $this->logger);
    }
    #endregion
}
