<?php

namespace Fifa\ConnectId\Sdk\Registration;

use Fifa\ConnectId\Sdk\ApiClient\Async\WaitTimeStrategyInterface;
use Fifa\ConnectId\Sdk\ApiClient\Async\WaitTimeStrategyLocator;

class CachePollingResponseAwaitersFactory implements ResponseAwaitersFactoryInterface
{
    /**
     * @var WaitTimeStrategyInterface
     */
    private $waitTimeStrategy;

    public function __construct(WaitTimeStrategyInterface $waitTimeStrategy = null)
    {
        $this->waitTimeStrategy = $waitTimeStrategy == null ? WaitTimeStrategyLocator::current() : $waitTimeStrategy;
    }

    /**
     * @inheritDoc
     */
    function create(CorrelationIdBasedItemProviderInterface $responsesCache): ResponseAwaiterInterface
    {
        return new CachePollingResponseAwaiter($responsesCache, $this->waitTimeStrategy);
    }
}