<?php

namespace App\Validator\Constraints;

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

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

        foreach ($value as $role) {
            if (!in_array($role, UserGroupPermissions::getRoles())) {
                $this->context->buildViolation($constraint->message)->addViolation();
            }
        }
    }
}