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

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

/**
 * 收支类型校验器
 *
 * @author Gqr
 * @since 2025/9/2 14:32
 */
public class IncomeExpenseTypeEnumValidator implements ConstraintValidator<IncomeExpenseTypeEnumValid, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (IncomeExpenseTypeEnum codeEnum : IncomeExpenseTypeEnum.values()) {
            if (ObjectUtil.equal(codeEnum.getCode(), value)) {
                return true;
            }
        }
        return false;
    }
}
