<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Api\Model\NationalIdentifierType;
use Fifa\ConnectId\Sdk\Registration\ValidationException;
use Fifa\ConnectId\Sdk\Util\Data\ISO3166CountryCode;
use Fifa\ConnectId\Sdk\Util\Data\Organisation\NationalIdentifier;

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

        ApiModelValidator::cannotBeNull($validationSubject, $validationSubjectName);
        ApiModelValidator::cannotBeNullOrWhitespace($validationSubject->getIdentifier(), $validationSubjectName.".identifier");

        $ignoreCase = false;
        ApiModelValidator::mustMatchEnumValue($validationSubject->getCountry(), XsdSchemaValuesResolver::getValues(ISO3166CountryCode::class),  $validationSubjectName.".country", $ignoreCase);
        ApiModelValidator::mustMatchEnumValue($validationSubject->getNationalIdentifierNature(), NationalIdentifier::getNationalIdentifiers(), $validationSubjectName.".nationalIdentifierNature");
    }
}