<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Model\PersonData;
use Fifa\ConnectId\Sdk\Registration\ValidationException;

class PersonDataValidator
{
    /**
     * Method that validates object provided and throws exception when object's properties are invalid
     *
     * @param PersonData|null $validationSubject
     * @param string $validationSubjectName
     * @return void
     * @throws ValidationException
     */
    public static function validate(?PersonData $validationSubject, string $validationSubjectName)
    {
        $validationSubjectName = ApiModelValidator::resolveValidationSubjectName($validationSubject, $validationSubjectName);

        ApiModelValidator::cannotBeNull($validationSubject, $validationSubjectName);

        ApiModelValidator::validateAllInCollection($validationSubject->getPersonNames(), PersonNameValidator::class, $validationSubjectName.".names");
        ContextTypeValidator::validate($validationSubject->getPersonType(), $validationSubjectName.".person");
    }
}