package com.ruoyi.project.business.enums;

import com.ruoyi.common.exception.ServiceErrorException;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum OperationEnum {
    /**
     * 等于
     */
    EQUAL("=", "00"),
    /**
     * 大于
     */
    GREATER_THAN(">", "01"),
    /**
     * 小于
     */
    LESS_THAN("<", "02"),
    /**
     * 大于等于
     */
    GREATER_THAN_OR_EQUAL(">=", "03"),
    /**
     * 小于等于
     */
    LESS_THAN_OR_EQUAL("<=", "04"),
    /**
     * 包含
     */
    CONTAIN("contains", "05"),
    /**
     * 不包含
     */
    NOT_CONTAIN("noContains", "06"),
    ;

    private String name;

    private String code;

    public static OperationEnum fromByValue(String value) {
        for (OperationEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getCode().equals(value)) {
                return auditFlowEnum;
            }
        }
        throw new ServiceErrorException("非法的函数类型");
    }

    public static OperationEnum fromByKey(String key) {
        for (OperationEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getName().equals(key)) {
                return auditFlowEnum;
            }
        }
        throw new ServiceErrorException("非法的函数类型");
    }

}
