package com.fjhx.enums.stock;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;
import org.springblade.core.tool.utils.StringPool;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 出库类型枚举
 */
@Getter
public enum OutTypeEnum {
    PURCHASE(1, "采购订单出库"),
    JD(2, "京东订单出库"),

    // ======== 手动出库明细 ========
    PICKING(3, "领料出库"),
    SALE(4, "销售出库"),
    RETURN_GOODS(5, "退货出库"),
    SCRAP(6, "报废出库"),
    // ======== 手动出库明细 ========

    TRANSFER(7, "调仓出库"),
    UNQUALIFIED_QUALITY_INSPECTION(8, "质检不合格出库"),

    ;

    private final int key;

    private final String value;

    OutTypeEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    private static final Map<Integer, OutTypeEnum> classMap = new HashMap<>();

    static {
        for (OutTypeEnum value : OutTypeEnum.values()) {
            classMap.put(value.getKey(), value);
        }
    }

    /**
     * 根据key获取枚举
     */
    public static OutTypeEnum getEnumByKey(Integer type) {
        return classMap.get(type);
    }

    /**
     * 通过key获取名称
     */
    public static String getValueByKey(Integer key) {
        OutTypeEnum outTypeEnum = classMap.get(key);

        if (ObjectUtil.isEmpty(outTypeEnum)) {
            return StringPool.EMPTY;
        }

        return outTypeEnum.getValue();
    }

    public static List<Integer> getHandleOutList() {
        return Arrays.asList(PICKING.key, SALE.key, RETURN_GOODS.key, SCRAP.key);
    }

}
