<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Api\Model\AddressType;
use Fifa\ConnectId\Sdk\Registration\ValidationException;
use Fifa\ConnectId\Sdk\Util\Data\ISO3166CountryCode;

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

        ApiModelValidator::cannotBeNull($validationSubject, $validationSubjectName);
        ApiModelValidator::cannotBeNullOrWhitespace($validationSubject->getTown(), $validationSubjectName.".town");
        ApiModelValidator::cannotBeNullOrWhitespace($validationSubject->getAddress(), $validationSubjectName.".address");

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