<?php
namespace Fifa\ConnectId\Sdk\Registration\Model;

use Fifa\ConnectId\Sdk\Model\PersonDuplicateWithDetails;

/**
 * Class RegistrationResult
 * @package Fifa\ConnectId\Sdk\Registration\Model
 */
class RegistrationResult
{
    /**
     * @var bool
     */
    private $isSuccessful;

    /**
     * @var string|null
     */
    private $uniqueFifaId;

    /**
     * @var PersonDuplicateWithDetails[]|null
     */
    private $personDuplicateWithDetails;

    /**
     * Constructor
     *
     * @param bool $isSuccessful
     * @param string|null $uniqueFifaId
     * @param PersonDuplicateWithDetails[]|null $personDuplicateWithDetails
     */
    private function __construct(bool $isSuccessful, ?string $uniqueFifaId, ?array $personDuplicateWithDetails)
    {
        $this->isSuccessful = $isSuccessful;
        $this->uniqueFifaId = $uniqueFifaId;
        $this->personDuplicateWithDetails = $personDuplicateWithDetails;
    }

    /**
     * String representation of the object
     *
     * @return string
     */
    public function __toString()
    {
        return  'IsSuccessful: ' . ($this->isSuccessful() ? 'true' : 'false') . ', UniqueFifaId: ' .
                (is_null($this->getUniqueFifaId()) ? 'null' : $this->getUniqueFifaId());
    }

    /**
     * Create an instance of RegistrationResult in case of successful registration
     *
     * @param string $uniqueFifaId
     * @return RegistrationResult
     */
    public static function success(string $uniqueFifaId): RegistrationResult
    {
        return new RegistrationResult(true, $uniqueFifaId, null);
    }

    /**
     * Create an instance of RegistrationResult in case of duplicates found
     *
     * @param array PersonDuplicateWithDetails[]
     * @return RegistrationResult
     */
    public static function duplicatesFound(array $personDuplicateWithDetails): RegistrationResult
    {
        return new RegistrationResult(false, null, $personDuplicateWithDetails);
    }

    /**
     * Getter for successful flag
     *
     * @return boolean
     */
    public function isSuccessful(): bool
    {
        return $this->isSuccessful;
    }

    /**
     * Getter for unique fifa ID
     *
     * @return string|null
     */
    public function getUniqueFifaId(): ?string
    {
        return $this->uniqueFifaId;
    }

    /**
     * Getter for person duplicate with details array
     *
     * @return PersonDuplicateWithDetails[]|null
     */
    public function getPersonDuplicateWithDetails(): ?array
    {
        return $this->personDuplicateWithDetails;
    }
}