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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.OrderStatisticsUnit;

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

/**
 * 生产单统计维度单位入参校验器
 */
public class OrgStatisticsUnitInEnumValidator implements ConstraintValidator<OrgStatisticsUnitInEnum, Integer> {

    @Override
    public void initialize(OrgStatisticsUnitInEnum 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;
        }
    }

}