<?php
declare(strict_types=1);

namespace FiloBlu\Refilo\Cron;

use FiloBlu\Refilo\Remote\RatingIndexer;
use Psr\Log\LoggerInterface;

/**
 * Class Cron
 * @package FiloBlu\Flow\Cron
 */
class Cron
{
    /**
     * @var RatingIndexer
     */
    private $ratingIndexer;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @param RatingIndexer $ratingIndexer
     * @param LoggerInterface $logger
     */
    public function __construct(
        RatingIndexer $ratingIndexer,
        LoggerInterface $logger
    )
    {
        $this->ratingIndexer = $ratingIndexer;
        $this->logger = $logger;
    }

    /**
     * @return $this
     */
    public function ratingIndexer(): Cron
    {
        try {
            $this->ratingIndexer->executeFull();
        } catch (\Throwable $e) {
            $this->logger->error('[Refilo RatingIndexer] Cron failed: ' . $e->getMessage());
            $this->logger->error($e->getTraceAsString());
        }
        return $this;
    }

}
