package com.backendsys.entity.validator;

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

import java.util.Arrays;
import java.util.List;

/**
 * 自定义注解 (逻辑实现)
 */
public class RangeFloatValidator implements ConstraintValidator<RangeFloat, Float> {
    private double min;
    private double max;

    @Override
    public void initialize(RangeFloat constrainAnnotation) {
        min = constrainAnnotation.min();
        max = constrainAnnotation.max();
    }

    @Override
    public boolean isValid(Float validValue, ConstraintValidatorContext constraintValidatorContext) {
        if (validValue == null || validValue == 0) { return true;  }
        return validValue >= min && validValue <= max;
    }

}
