<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Registration\ValidationException;

class EmailValidator
{
    const PATTERN = "/^(([^<>()\\[\\]\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@(([^<>()\\[\\]\\\.,;:\\s@\"]+\\.)+[a-zA-Z]{2,})\$/";

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

        ApiModelValidator::mustMatchPattern($validationSubject, self::PATTERN, $validationSubjectName);
    }
}