<?php

namespace CleantalkSP\SpbctWP\FSWatcher;

use CleantalkSP\Common\RateLimit\RateLimiterConfig;
use CleantalkSP\SpbctWP\FSWatcher\Repository\FileRepository;
use CleantalkSP\SpbctWP\FSWatcher\Storage\FileStorage;
use CleantalkSP\SpbctWP\SpbcRateLimit\SpbcRateLimiter;

class Service
{
    public static function setStorage($storage = 'file')
    {
        switch ($storage) {
            case 'file':
            default:
                Controller::$storage = FileStorage::class;
                break;
            // case 'customdb':
            // Controller::$storage = CustomDBStorage::class;
            // Controller::$repository = CustomDBStorage::class;
            // break;
            // case 'db':
            // Controller::$storage = DBStorage::class;
            // Controller::$repository = DBStorage::class;
            // break;
        }
    }

    /**
     * Set snapshots to completed status
     *
     * @return void
     */
    public static function setAllJournalsAsCompleted()
    {
        $storage = Controller::$storage;
        $storage::setAllJournalsAsCompleted();
    }

    public static function rateLimitPassed()
    {
        $rate_limit_config = new RateLimiterConfig('fswatcher_actions', 30, 60);
        $rate_limiter = new SpbcRateLimiter($rate_limit_config);
        return $rate_limiter->checkPassed();
    }
}
