package com.cf.imes.module.system.validation.menu;

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.system.enums.permission.MenuTypeEnum;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * 菜单类型校验器
 *
 * @author Gqr
 * @since 2024/10/21 11:26
 */
public class MenuTypeValidator implements ConstraintValidator<MenuTypeValid, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (MenuTypeEnum typeEnum : MenuTypeEnum.values()) {
            if (ObjectUtil.equal(typeEnum.getType(), value)) {
                return true;
            }
        }
        return false;
    }
}
