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

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

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

/**
 * 产品详情购买方式校验器
 */
public class ProductTypeValidator implements ConstraintValidator<ProductType, Integer> {

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

}
