<?php

namespace Fifa\ConnectId\Sdk\Registration\Model;

use Fifa\ConnectId\Sdk\ActorResolver\ActorResolverInterface;
use Fifa\ConnectId\Sdk\ActorResolver\SimpleActorResolver;
use Fifa\ConnectId\Sdk\HashedPersonProcessor\HashedPersonProcessorInterface;
use Fifa\ConnectId\Sdk\Storage\PersonDetailsStorageInterface;

/**
 * Class RegistrationFacadeSettings
 * @package Fifa\ConnectId\Sdk\Registration\Model
 */
class RegistrationFacadeSettings
{
    /**
     * @var PersonDetailsStorageInterface
     */
    private $storage;

    /**
     * @var int
     */
    private $receivingOperationExecutionTime;

    /**
     * @var int
     */
    private $pollingIntervalMilliseconds;

    /**
     * @var ActorResolverInterface
     */
    private $actorResolver;

    /**
     * @var HashedPersonProcessorInterface
     */
    private $hashedPersonProcessor;

    /**
     * Constructor
     *
     * @param PersonDetailsStorageInterface $storage
     * @param int $receivingOperationExecutionTime - in seconds
     * @param int $pollingIntervalMilliseconds
     * @param ActorResolverInterface|null $actorResolver
     * @param HashedPersonProcessorInterface|null $hashedPersonProcessor
     */
    public function __construct(
        PersonDetailsStorageInterface $storage,
        int $receivingOperationExecutionTime = 60,
        int $pollingIntervalMilliseconds = 50,
        ?ActorResolverInterface $actorResolver = null,
        ?HashedPersonProcessorInterface $hashedPersonProcessor = null
    ) {
        $this->storage = $storage;
        $this->receivingOperationExecutionTime = $receivingOperationExecutionTime;
        $this->pollingIntervalMilliseconds = $pollingIntervalMilliseconds;
        $this->actorResolver = $actorResolver;
        $this->hashedPersonProcessor = $hashedPersonProcessor;
    }

    /**
     * String representation of the object
     *
     * @return string
     */
    public function __toString()
    {
        return 'ReceivingOperationExecutionTime: ' . $this->getReceivingOperationExecutionTime();
    }

    /**
     * Getter for Storage mechanism
     *
     * @return PersonDetailsStorageInterface
     */
    public function getStorage(): PersonDetailsStorageInterface
    {
        return $this->storage;
    }

    /**
     * Getter for message receiving operation execution time
     *
     * @return int
     */
    public function getReceivingOperationExecutionTime(): int
    {
        return $this->receivingOperationExecutionTime;
    }

    /**
     * Getter for pooling interval milliseconds
     *
     * @return int
     */
    public function getPollingIntervalMilliseconds(): int
    {
        return $this->pollingIntervalMilliseconds;
    }

    /**
     * Getter for actor resolver
     *
     * @return ActorResolverInterface
     */
    public function getActorResolver(): ActorResolverInterface
    {
        if (is_null($this->actorResolver)) {
            $this->actorResolver = SimpleActorResolver::emptyActor();
        }

        return $this->actorResolver;
    }

    /**
     * Setter for actor resolver
     *
     * @param ActorResolverInterface $actorResolver
     * @return RegistrationFacadeSettings
     */
    public function setActorResolver(ActorResolverInterface $actorResolver): RegistrationFacadeSettings
    {
        $this->actorResolver = $actorResolver;
        return $this;
    }

    /**
     * Getter for hashed person processor
     *
     * @return HashedPersonProcessorInterface|null
     */
    public function getHashedPersonProcessor(): ?HashedPersonProcessorInterface
    {
        return $this->hashedPersonProcessor;
    }
}