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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.MachineTypeEnum;

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

/**
 * 机台类型校验器
 *
 * @author Gqr
 * @since 2024/10/16 10:21
 */
public class MachineTypeValidator implements ConstraintValidator<MachineTypeValid, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (MachineTypeEnum typeEnum : MachineTypeEnum.values()) {
            if (ObjectUtil.equal(typeEnum.getType(), value)) {
                return true;
            }
        }
        return false;
    }
}
