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

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.system.enums.products.ProductStatusEnum;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.Objects;

/**
 * 产品状态校验器
 */
public class ProductStatusValidator implements ConstraintValidator<ProductStatus, Integer> {

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (ProductStatusEnum statusEnum : ProductStatusEnum.values()) {
            if (Objects.equals(statusEnum.getStatus(), value)) {
                return true;
            }
        }
        return false;
    }
}
