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

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

/**
 * 交易类型校验器
 *
 * @author Gqr
 * @since 2025/9/2 14:25
 */
public class TradeTypeEnumValidator implements ConstraintValidator<TradeTypeEnumValid, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (TradeTypeEnum codeEnum : TradeTypeEnum.validArr()) {
            if (ObjectUtil.equal(codeEnum.getCode(), value)) {
                return true;
            }
        }
        return false;
    }
}
