package com.fjhx.wms.entity.stock.emums;

import cn.hutool.core.util.ObjectUtil;
import com.fjhx.common.enums.InOutType;
import com.ruoyi.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@AllArgsConstructor
@Getter
public enum JournalType {

    //出库
    PROD_PROOFING_OUT(InOutType.OUT, 0, "生产打样", ""),//手动出库
    PROD_EXCEED_OUT(InOutType.OUT, 1, "生产超领", ""),//手动出库
    SALE_OUT(InOutType.OUT, 2, "销售出库", ""),//手动出库
    BORROW_OUT(InOutType.OUT, 3, "借用出库", ""),//手动出库
    REPAIR_EXCEED_OUT(InOutType.OUT, 4, "补单超领", ""),//待出库-APP补单
    LOSE_EXCEED_OUT(InOutType.OUT, 5, "丢件超领", ""),//待出库-APP丢单
    PURCHASE_RETURN_OUT(InOutType.OUT, 6, "采购退货", ""),//待出库-采购退货
    TRANSFER_OUT(InOutType.OUT, 7, "调拨出库", ""),//调仓
    STOCK_CHECK_OUT(InOutType.OUT, 8, "盘亏出库", ""),//库存盘点
    PROD_OUT(InOutType.OUT, 9, "生产出库", ""),//待出库-生产出库
    OTHER_OUT(InOutType.OUT, 10, "其他出库", ""),//手动出库-其他


    //入库
    RESTITUTION_IN(InOutType.IN, 100, "借用归还", ""),//手动入库
    MATERIAL_RETURN_IN(InOutType.IN, 101, "退料入库", ""),//手动入库
    DISCARD_MATERIAL_IN(InOutType.IN, 102, "废料入库", ""),//手动入库
    LOSE_IN(InOutType.IN, 103, "丢件寻回", ""),//手动入库
    PURCHASE_IN(InOutType.IN, 104, "采购入库", ""),//待入库-采购入库
    TRANSFER_IN(InOutType.IN, 105, "调拨入库", ""),//调仓
    STOCK_CHECK_IN(InOutType.IN, 106, "盘盈入库", ""),//库存盘点
    COMPLETION_IN(InOutType.IN, 107, "完工入库", ""),//待入库-完工入库
    EXCEED_REST_IN(InOutType.IN, 108, "超领归还", ""),//手动入库
    ERR_REST_IN(InOutType.IN, 109, "错领归还", ""),
    OTHER_IN(InOutType.IN, 110, "其他入库", "");//手动出库-其他

    ;//手动入库

    private final static Map<Integer, JournalType> map = new HashMap<>();

    static {
        for (JournalType value : JournalType.values()) {
            map.put(value.detailType, value);
        }
    }

    public static JournalType getByDetailType(Integer detailType) {
        JournalType journalType = map.get(detailType);
        if (ObjectUtil.isEmpty(journalType)) {
            throw new ServiceException("未知流水类型");
        }
        return journalType;
    }

    /**
     * 出入库类型
     */
    private final InOutType type;

    /**
     * 详细类型
     */
    private final Integer detailType;

    /**
     * 信息类型说明
     */
    private final String detailTypeRemark;

    /**
     * 关联业务表名
     */
    private final String linkBusinessTableName;

}
