package com.cf.imes.module.executor.validation.order;

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.executor.enums.OrderStatusEnum;

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

/**
 * 订单状态校验器
 *
 * @author Gqr
 * @since 2024/10/18 16:38
 */
public class OrderStatusValidator implements ConstraintValidator<OrderStatusValid, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            if (Objects.equals(statusEnum.getStatus(), value)) {
                return true;
            }
        }
        return false;
    }
}
