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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;

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

/**
 * 自定义报表数据源类型入参校验器
 *
 * @author Gqr
 * @since 2024/7/17 9:33
 */
public class ReportDatasourceTypeInEnumValidator implements ConstraintValidator<ReportDatasourceTypeInEnum, String> {

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

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        ReportDatasourceTypeEnum byType = ReportDatasourceTypeEnum.fromDesc(value);
        if (ObjectUtil.isNotNull(byType)) {
            return true;
        } else {
            return false;
        }
    }

}

