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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.system.enums.config.SystemConfigTypeEnum;

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


/**
 * 系统配置类型校验器
 *
 * @author Gqr
 * @since 2024/11/8 14:01
 */
public class SystemConfigTypeEnumValidator implements ConstraintValidator<SystemConfigTypeEnumValid, Integer> {
    @Override
    public void initialize(SystemConfigTypeEnumValid constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

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