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

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

import java.util.Objects;

/**
 * 时长单位校验器
 *
 * @author Gqr
 * @since 2025/8/11 14:19
 */
public class DurationUnitValidator implements ConstraintValidator<DurationUnitValid, Integer> {

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (DurationUnitEnum unitEnum : DurationUnitEnum.values()) {
            if (Objects.equals(unitEnum.getCode(), value)) {
                return true;
            }
        }
        return false;
    }
}
