package org.dromara.zhishu.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.exception.ServiceException;

import java.util.ArrayList;
import java.util.List;

/**
 * 操作库存类型枚举
 */
@Getter
@AllArgsConstructor
public enum OperationInventoryTypeEnum {

    INCREASE_INVENTORY(1, "增加库存"),

    REDUCE_INVENTORY(2, "减少库存");

    /**
     * code
     */
    private final Integer code;

    /**
     * message
     */
    private final String msg;

    public static List<Integer> getOperationInventoryTypeEnumList() {
        List<Integer> operationInventoryTypeEnumList = new ArrayList<>();
        for (OperationInventoryTypeEnum item : values()) {
            operationInventoryTypeEnumList.add(item.getCode());
        }
        return operationInventoryTypeEnumList;
    }

    public static OperationInventoryTypeEnum valueOfCode(int code) {
        for (OperationInventoryTypeEnum type : values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        throw new ServiceException("未知操作库存类型code: " + code);
    }

}
