<?php

namespace Fifa\ConnectId\Sdk\ApiModelValidation;

use Fifa\ConnectId\Sdk\Registration\ValidationException;

class WebAddressValidator
{
    const PATTERN = '/^https?:\/\/(([\p{L}\p{N}]([\p{L}\p{N}@:%_\+~#=-]{0,61}[\p{L}\p{N}])?\.)+[\p{L}\p{N}]{2,63})(\/[-\p{L}\p{N}()!@:%_\+.~#?&\/=]*)?$/u';

    /**
     * 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)
            ? "WebAddress"
            : $validationSubjectName;

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