package com.cf.imes.module.executor.validation.order;

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.executor.enums.OrderStatisticsUnit;

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

/**
 * 生产单统计维度单位入参校验器
 *
 * @author Gqr
 * @since 2024/7/17 9:33
 */
public class OrderStatisticsUnitInEnumValidator implements ConstraintValidator<OrderStatisticsUnitInEnum, Integer> {

    @Override
    public void initialize(OrderStatisticsUnitInEnum constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        OrderStatisticsUnit unit = OrderStatisticsUnit.fromValue(value);
        if (ObjectUtil.isNotNull(unit)) {
            return true;
        } else {
            return false;
        }
    }

}

