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

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

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

/**
 * 状态校验
 */
public class CommonStatusValidator implements ConstraintValidator<ValidCommonStatus, Integer> {

    private ValidCommonStatus annotation;

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

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (value == null) {
            value = RemainPlateStatusEnum.UNUSED.getStatus(); // 默认值为未使用
        }
        return value == RemainPlateStatusEnum.UNUSED.getStatus() || value == RemainPlateStatusEnum.USED.getStatus();
    }
}
