<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Api\Model\AddRegistrationsRequestType;
use Fifa\ConnectId\Sdk\Api\Model\AddressType;
use Fifa\ConnectId\Sdk\Api\Model\BulkDeactivateRegistrationsRequestType;
use Fifa\ConnectId\Sdk\Api\Model\FacilityLocalType;
use Fifa\ConnectId\Sdk\Api\Model\FieldType;
use Fifa\ConnectId\Sdk\Api\Model\FindFacilitiesRequestType;
use Fifa\ConnectId\Sdk\Api\Model\FindOrganisationsRequestType;
use Fifa\ConnectId\Sdk\Api\Model\GetDuplicatesByFIFAIdRequestType;
use Fifa\ConnectId\Sdk\Api\Model\GetDuplicatesRequestType;
use Fifa\ConnectId\Sdk\Api\Model\HashedNameType;
use Fifa\ConnectId\Sdk\Api\Model\LocalNameType;
use Fifa\ConnectId\Sdk\Api\Model\MatchOfficialRegistrationType;
use Fifa\ConnectId\Sdk\Api\Model\NationalAssociationsOnboardedRequestType;
use Fifa\ConnectId\Sdk\Api\Model\NationalIdentifierType;
use Fifa\ConnectId\Sdk\Api\Model\OrganisationLocalType;
use Fifa\ConnectId\Sdk\Api\Model\OrganisationOfficialRegistrationType;
use Fifa\ConnectId\Sdk\Api\Model\PersonDeactivateType;
use Fifa\ConnectId\Sdk\Api\Model\PersonDuplicateMatchType;
use Fifa\ConnectId\Sdk\Api\Model\PersonRegistrationsType;
use Fifa\ConnectId\Sdk\Api\Model\PersonType;
use Fifa\ConnectId\Sdk\Api\Model\PictureEmbeddedType;
use Fifa\ConnectId\Sdk\Api\Model\PictureLinkType;
use Fifa\ConnectId\Sdk\Api\Model\PictureType;
use Fifa\ConnectId\Sdk\Api\Model\PlayerRegistrationType;
use Fifa\ConnectId\Sdk\Api\Model\RegisterPersonRequestType;
use Fifa\ConnectId\Sdk\Api\Model\SearchAddressType;
use Fifa\ConnectId\Sdk\Api\Model\SupportedDisciplineType;
use Fifa\ConnectId\Sdk\Api\Model\TeamOfficialRegistrationType;
use Fifa\ConnectId\Sdk\Api\Model\UpdatePersonRequestType;
use Fifa\ConnectId\Sdk\Api\Model\UpdateRegistrationsRequestType;
use Fifa\ConnectId\Sdk\Api\Model\ComplianceAndPaymentManagerType;
use Fifa\ConnectId\Sdk\Model\PersonData;
use Fifa\ConnectId\Sdk\Model\PersonName;
use Fifa\ConnectId\Sdk\Registration\ValidationException;

class ContextTypeValidator
{
    /**
     * @var string[]
     */
    private static $validatorsClassesMap;

    static function __init()
    {
        self::$validatorsClassesMap = array
        (
            AddRegistrationsRequestType::class => AddRegistrationsRequestTypeValidator::class,
            AddressType::class => AddressTypeValidator::class,
            BulkDeactivateRegistrationsRequestType::class => BulkDeactivateRegistrationsRequestTypeValidator::class,
            FacilityLocalType::class => FacilityLocalTypeValidator::class,
            FieldType::class => FieldTypeValidator::class,
            FindFacilitiesRequestType::class => FindFacilitiesRequestTypeValidator::class,
            FindOrganisationsRequestType::class => FindOrganisationsRequestTypeValidator::class,
            GetDuplicatesByFIFAIdRequestType::class => GetDuplicatesByFIFAIdRequestTypeValidator::class,
            GetDuplicatesRequestType::class => GetDuplicatesRequestTypeValidator::class,
            HashedNameType::class => HashedNameTypeValidator::class,
            LocalNameType::class => LocalNameTypeValidator::class,
            MatchOfficialRegistrationType::class => MatchOfficialRegistrationTypeValidator::class,
            NationalAssociationsOnboardedRequestType::class => NationalAssociationsOnboardedRequestTypeValidator::class,
            NationalIdentifierType::class => NationalIdentifierTypeValidator::class,
            OrganisationLocalType::class => OrganisationLocalTypeValidator::class,
            OrganisationOfficialRegistrationType::class => OrganisationOfficialRegistrationTypeValidator::class,
            PersonData::class => PersonDataValidator::class,
            PersonDeactivateType::class => PersonDeactivateTypeValidator::class,
            PersonDuplicateMatchType::class => PersonDuplicateMatchTypeValidator::class,
            PersonName::class => PersonNameValidator::class,
            PersonRegistrationsType::class => PersonRegistrationsTypeValidator::class,
            PersonType::class => PersonTypeValidator::class,
            PictureEmbeddedType::class => PictureEmbeddedTypeValidator::class,
            PictureLinkType::class => PictureLinkTypeValidator::class,
            PictureType::class => PictureTypeValidator::class,
            PlayerRegistrationType::class => PlayerRegistrationTypeValidator::class,
            RegisterPersonRequestType::class => RegisterPersonRequestTypeValidator::class,
            SearchAddressType::class => SearchAddressTypeValidator::class,
            SupportedDisciplineType::class => SupportedDisciplineTypeValidator::class,
            TeamOfficialRegistrationType::class => TeamOfficialRegistrationTypeValidator::class,
            UpdatePersonRequestType::class => UpdatePersonRequestTypeValidator::class,
            UpdateRegistrationsRequestType::class => UpdateRegistrationsRequestTypeValidator::class,
            ComplianceAndPaymentManagerType::class => ComplianceAndPaymentManagerTypeValidator::class,
        );
    }

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

        $objectClass = get_class($validationSubject);
        if (!array_key_exists($objectClass, self::$validatorsClassesMap)) {
            throw new ValidationException("There's no validator registered for object of: " . $objectClass);
        }

        $validatorClass = self::$validatorsClassesMap[$objectClass];
        ApiModelValidator::invokeValidationMethodForValidator($validatorClass, $validationSubject, $validationSubjectName);
    }
}

ContextTypeValidator::__init();