<?php
namespace Fifa\ConnectId\Sdk\HashedPersonProcessor;
use Fifa\ConnectId\Sdk\Model\HashedPersonType;
use Fifa\ConnectId\Sdk\Api\Model\RegisterPersonRequestType;

/**
 * Class RegisterPersonRequestProcessorAdapter
 * @package Fifa\ConnectId\Sdk\HashedPersonProcessor
 */
class RegisterPersonRequestProcessorAdapter implements RegisterPersonRequestProcessorInterface
{
    /**
     * @var HashedPersonProcessorInterface
     */
    private $hashedPersonProcessor;

    /**
     * RegisterPersonRequestProcessorAdapter constructor.
     * @param HashedPersonProcessorInterface $hashedPersonProcessor
     */
    public function __construct(HashedPersonProcessorInterface $hashedPersonProcessor)
    {
        $this->hashedPersonProcessor = $hashedPersonProcessor;
    }

    /**
     * @param RegisterPersonRequestType $requestType
     * @return RegisterPersonRequestType
     */
    public function process(RegisterPersonRequestType $requestType): RegisterPersonRequestType
    {
        $hashedPersonType = new HashedPersonType();
        $hashedPersonType->setNameHashes($requestType->getNameHashes())
            ->setPerson($requestType->getPerson())
            ->setLocalId($requestType->getLocalId());
        $processedHashedPerson = $this->hashedPersonProcessor->process($hashedPersonType);

        $registerPersonRequestType = new RegisterPersonRequestType();
        $registerPersonRequestType->setNameHashes($processedHashedPerson->getNameHashes())
            ->setPerson($processedHashedPerson->getPerson())
            ->setLocalId($processedHashedPerson->getLocalId());
        return $registerPersonRequestType;
    }
}