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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.system.enums.pay.PayChannelCodeEnum;

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

/**
 * 支付渠道编码校验器
 *
 * @author Gqr
 * @since 2025/4/18 10:22
 */
public class PayChannelCodeValidator implements ConstraintValidator<PayChannelCodeValid, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (PayChannelCodeEnum codeEnum : PayChannelCodeEnum.values()) {
            if (ObjectUtil.equal(codeEnum.getCode(), value)) {
                return true;
            }
        }
        return false;
    }
}
