package com.ruoyi.warehouseBusiness.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

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

/**
 * @author caifc
 * @date 2021-10-22 17:19
 */
@Getter
@AllArgsConstructor
public enum WarehouseTypeEnum {

    // 仓储业务类型


    KCZZ("KCZZ", "库存总帐", "storageType"),

    SJRK("SJRK", "入库", "storageType"),

    SJCK("SJCK", "出库", "storageType"),

    HQZY("HQZY", "货转", "storageType"),

    CKDB("CKDB", "调拨", "storageType"),

    HWTG("HWTG", "货物通关", "storageType"),

    JSCCF("JSCCF", "计算仓储费", "storageType"),

    SJRK_REVOKE("SJRKRevoke", "撤销入库", "storageType"),

    SJCK_REVOKE("SJCKRevoke", "撤销出库", "storageType"),

    CKDB_REVOKE("CKDBRevoke", "撤销调拨", "storageType"),

    HWTG_REVOKE("HWTGRevoke", "撤销通关", "storageType"),

    HQZY_REVOKE("HQZYRevoke", "撤销货权转移", "storageType"),

    //是否已计算仓储费

    CALCULATE("T", "已计算", "storageFee"),

    NOT_CALCULATE("F", "未计算", "storageFee"),



    // 状态
    INIT("1", "新建", "storageStatus"),
    SAVE("2", "保存", "storageStatus"),
    DISMISS("3", "请核驳回", "storageStatus"),
    SUBMIT("4", "请核", "storageStatus"),
    UNDER_REVIEW("5", "请核中", "storageStatus"),
    APPROVE("6", "请核完成", "storageStatus"),


    // 仓库主表明细状态
    DETAILED_STATUS_PLAN("1", "计划", "itemStatus"),
    DETAILED_STATUS_WAITING("2", "待xx", "itemStatus"),
    DETAILED_STATUS_PROCESSING("3", "xx中", "itemStatus"),
    DETAILED_STATUS_PROCESSED("4", "已xx", "itemStatus"),


    // 编号生成简写

    SJRK_NO("RK", "入库", "warehouseAbbreviation"),
    SJCK_NO("CK", "出库", "warehouseAbbreviation"),
    CKDB_NO("DB", "调拨", "warehouseAbbreviation"),
    HQZY_NO("HZ", "货转", "warehouseAbbreviation"),

    FYBG_NO("FYBG", "费用变更", "warehouseAbbreviation"),


    // 件数
    BOX_NUM("1", "件", "warehouseUnit"),
    // 毛重
    GROSS_WEIGHT("2", "吨", "warehouseUnit"),
    // 净重
    NET_WEIGHT("3", "吨", "warehouseUnit"),
    // 尺码
    MEASURE("4", "吨", "warehouseUnit"),
    // 统一
    FIXED("5", "吨", "warehouseUnit"),

    // 是否计入库存总帐
    INVENTORY("0", "计入库存总帐", "generalLedger"),
    NOT_INVENTORY("1", "计入库存总帐", "generalLedger"),

    // 根据提单号、客户、仓库查询商品信息类型
    BY_MBLNO("mblno", "根据提单号查询", "queryType"),
    BY_CPRP("corp", "根据客户查询", "queryType"),
    BY_WAREHOUSE("warehouse", "根据仓库查询", "queryType"),


    // 查询库存帐操作
    CONFIRM_OPERATION("0", "确认入库、出库、货转、调拨", "queryType"),
    UNDO_OPERATION("1", "撤回入库、出库、货转、调拨", "queryType"),

    // 是否判断箱型
    JUDGE_BOX("1", "判断箱型", "judge"),
    NOT_JUDGE_BOX("0", "非判断箱型", "judge"),


    ;
    // 值
    private final String type;
    // 名称
    private final String name;
    // 业务
    private final String businessType;

    public static WarehouseTypeEnum fromType(String tp) {
        for (WarehouseTypeEnum type : WarehouseTypeEnum.values()) {
            if (Objects.equals(type.getType(), tp)) {
                return type;
            }
        }
        throw new IllegalArgumentException("warehouse type not exist");
    }

    public static WarehouseTypeEnum fromTypeAndBusinessType(String tp, String businessTyoe) {
        for (WarehouseTypeEnum type : WarehouseTypeEnum.values()) {
            if (Objects.equals(type.getType(), tp) && businessTyoe.equals(type.getBusinessType())) {
                return type;
            }
        }
        throw new IllegalArgumentException("warehouse type not exist");
    }

    // 获取业务类型集合
    public static List<String> getWarehousingType() {
        List<String> typList = new ArrayList<>();
        typList.add(SJRK.type);
        typList.add(SJCK.type);
        typList.add(HQZY.type);
        typList.add(CKDB.type);
        typList.add(HWTG.type);
        return typList;
    }

    /**
     * 获取计费单位信息
     *
     * @param unit
     * @return
     */
    public static String getUnitCharging(Long unit) {
        if (Objects.equals(Long.parseLong(BOX_NUM.type), unit)) {
            return BOX_NUM.name;
        } else if (Objects.equals(Long.parseLong(GROSS_WEIGHT.type), unit)) {
            return GROSS_WEIGHT.name;
        } else if (Objects.equals(Long.parseLong(NET_WEIGHT.type), unit)) {
            return NET_WEIGHT.name;
        } else if (Objects.equals(Long.parseLong(MEASURE.type), unit)) {
            return MEASURE.name;
        } else if (Objects.equals(Long.parseLong(FIXED.type), unit)) {
            return FIXED.name;
        }
        throw new IllegalArgumentException("warehouse Billing unit does not exist");
    }

}
