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

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

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.Objects;

/**
 * 状态校验器
 *
 * @author Gqr
 * @since 2024/10/12 9:50
 */
public class CommonStatusValidator implements ConstraintValidator<CommonStatus, Integer> {

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (CommonStatusEnum statusEnum : CommonStatusEnum.values()) {
            if (Objects.equals(statusEnum.getStatus(), value)) {
                return true;
            }
        }
        return false;
    }
}
