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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.system.enums.permission.MenuSourceTypeEnum;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

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