package link.at17.mid.tushare.data.validator;

import java.util.Set;

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

/**
 * 允许枚举的验证器
 */
public class AllowedEnumValidator implements IValidator, ConstraintValidator<AllowedEnum, Enum<?>> {
    private Set<String> allowed;

    @Override
    public void initialize(AllowedEnum anno) {
        allowed = Set.of(anno.value());
    }

    @Override
    public boolean isValid(Enum<?> val, ConstraintValidatorContext ctx) {
        return val == null || allowed.contains(val.name());
    }
}