package com.cf.imes.module.report.validation.template;

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;

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

/**
 * 自定义报表模板类型入参校验器
 *
 * @author Gqr
 * @since 2024/7/17 9:33
 */
public class ReportTemplateTypeInEnumValidator implements ConstraintValidator<ReportTemplateTypeInEnum, Integer> {

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

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

}

