<?php

namespace App\Validator\Constraints;

use App\Model\OrganizationalUnitP2PModes;
use App\Model\UserGroupPermissions;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

class OrganizationalUnitMulticastPortValidator extends ConstraintValidator
{
    public const int minPort = 9000;
    public const int maxPort = 9098;

    public function validate($value, Constraint $constraint): void
    {
        if (null === $value) {
            return;
        }

        if ($value % 2 !== 0) {
            $this->context->buildViolation('El puerto debe ser un número par y encontrarse entre el 9000 y el 9098.')->addViolation();
            return;
        }

        if ($value < self::minPort || $value > self::maxPort) {
            $this->context->buildViolation($constraint->message)->addViolation();
            return;
        }
    }
}
