package com.cf.imes.module.executor.validation.manage.type;

import com.cf.imes.module.executor.enums.manage.remainPlate.RemainPlateUseTypeEnum;

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

/**
 * 使用类型校验
 */
public class TypeFieldValidator implements ConstraintValidator<ValidTypeField, Integer> {

    private ValidTypeField annotation;

    @Override
    public void initialize(ValidTypeField constraintAnnotation) {
        this.annotation = constraintAnnotation;
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        // 如果值为 null，则不做校验，直接返回 true
        if (value == null) {
            value = RemainPlateUseTypeEnum.TYPE_ZERO.getStatus(); // 默认值为未使用
        }
        return value == RemainPlateUseTypeEnum.TYPE_ONE.getStatus() ||
                value == RemainPlateUseTypeEnum.TYPE_TWO.getStatus() ||
                value == RemainPlateUseTypeEnum.TYPE_THREE.getStatus() ||
                value == RemainPlateUseTypeEnum.TYPE_ZERO.getStatus();
    }
}