<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Api\Model\FacilityLocalType;
use Fifa\ConnectId\Sdk\Registration\ValidationException;
use Fifa\ConnectId\Sdk\Util\Data\ISO3166CountryCode;
use Fifa\ConnectId\Sdk\Util\Data\ISO6392LanguageCode;
use Fifa\ConnectId\Sdk\Util\Data\Status;

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

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

        ApiModelValidator::cannotBeNullOrWhitespace($validationSubject->getLocalName(), $validationSubjectName.".localName");
        ApiModelValidator::cannotBeNullOrWhitespace($validationSubject->getInternationalName(), $validationSubjectName.".internationalName");

        ApiModelValidator::validateAllowNull($validationSubject->getFacilityFIFAId(), FifaIdValidator::class, $validationSubjectName.".facilityFIFAId");
        ApiModelValidator::validateAllowNull($validationSubject->getParentFacilityFIFAId(), FifaIdValidator::class, $validationSubjectName.".parentFacilityFIFAId");
        ApiModelValidator::validateDoNotAllowNull($validationSubject->getOrganisationFIFAId(), FifaIdValidator::class, $validationSubjectName.".organisationFIFAId");

        ApiModelValidator::mustMatchEnumValue($validationSubject->getStatus(), Status::getStatuses(), $validationSubjectName.".status");
        $ignoreCase = false;
        ApiModelValidator::mustMatchEnumValue($validationSubject->getLocalLanguage(), XsdSchemaValuesResolver::getValues(ISO6392LanguageCode::class), $validationSubjectName.".localLanguage", $ignoreCase);
        ApiModelValidator::mustMatchEnumValue($validationSubject->getLocalCountry(), XsdSchemaValuesResolver::getValues(ISO3166CountryCode::class), $validationSubjectName.".localCountry", $ignoreCase);

        ContextTypeValidator::validate($validationSubject->getOfficialAddress(), $validationSubjectName.".officialAddress");

        ApiModelValidator::validateAllInCollectionAllowNull($validationSubject->getLocalFacilityName(), LocalNameTypeValidator::class, $validationSubjectName.".localFacilityName");
        ApiModelValidator::validateAllInCollectionAllowNull($validationSubject->getField(), FieldTypeValidator::class, $validationSubjectName.".field");
    }
}