package com.slodon.b2b2c.util;

import com.slodon.b2b2c.core.util.StringUtil;

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

/**
 * 快递鸟电子面单所需字段获取
 */
public enum FaceSheetNeedField {

    /**
     * 电子面单所需字段
     */
    EMS("EMS", "customerName:大客户号,customerPwd:APP_SECRET"),
    SF("SF", "monthCode:月结号(选填)"),
    YZBK("YZBK", ""),
    YZPY("YZPY", ""),
    ZJS("ZJS", "customerName:分仓标识(选填)"),
    LHT("LHT", ""),
    EST365("EST365", ""),
    WTWL("WTWL", ""),
    DYJ("DYJ", ""),
    UAPEX("UAPEX", "customerName:客户ID,customerPwd:客户密钥"),
    STO("STO", "customerName:客户简称,customerPwd:客户密码,sendSite:归属网点"),
    DBL("DBL", "customerName:月结编码"),
    JD("JD", "customerName:商家编码"),
    XFEX("XFEX", "customerName:客户平台ID,customerPwd:客户平台验证码,sendSite:客户商号ID或仓库ID"),
    //    HHTT("HHTT", "customerName:客户账号,customerPwd:客户密码,sendSite:网点名称"),
    SURE("SURE", "customerName:客户号,sendSite:网点编号(仓库号),sendStaff:收件快递员(网点提供)"),
    KYSY("KYSY", "customerName:客户编码,monthCode:付款账号(选填)"),
    PJ("PJ", "customerName:月结号,customerPwd:密钥"),
    CND("CND", "customerName:客户编码,customerPwd:客户密钥"),
    JTSD("JTSD", "customerName:客户号,customerPwd:密码"),
    DNWL("DNWL", "customerName:账号,customerPwd:密码"),
    SNWL("SNWL", "customerName:账号,customerPwd:密码"),
    ZYE("ZYE", "customerName:客户编号,sendSite:网点编码"),
    ZTO("ZTO", "customerName:客户账号,customerPwd:接口密码"),
    YD("YD", "customerName:白马账号,customerPwd:接口联调密码"),
    HTKY("HTKY", "customerName:操作编码,customerPwd:ERP秘钥"),
    YTO("YTO", "customerName:客户编码,monthCode:密钥"),
    YCWL("YCWL", "customerName:商户代码,sendSite:网点名称"),
    UC("UC", "customerName:客户号,customerPwd:密码"),
    JGSD("JGSD", "customerName:客户号"),
    FWX("FWX", "customerName:取号账户,customerPwd:取号密码"),
    //    ANE("ANE", "customerName:客户号,sendSite:网点名称(仅数字部分)"),
    TLWL("TLWL", ""),
    HOAU("HOAU", "customerName:客户编号,customerPwd:网点名称,sendSite:网点编码"),
    DBLKY("DBLKY", "customerName:月结编码"),
    ANEKY("ANEKY", "customerName:客户编码,customerPwd:客户秘钥"),
    JDKY("JDKY", "customerName:商家编码,customerPwd:事业部编码(EBU开头)"),
    LB("LB", "customerName:电子面单账号,customerPwd:密码"),
    HTKYKY("HTKYKY", "customerName:账户信息,customerPwd:账户密码"),
    ZTOKY("ZTOKY", "customerName:商家CP,customerPwd:商家秘钥"),
    CNEX("CNEX", "customerName:客户编码"),
    YDKY("YDKY", "customerName:客户ID,customerPwd:接口密钥"),
    SX("SX", "customerName:客户编号,customerPwd:客户秘钥,sendSite:网点编码"),
    YMDD("YMDD", "customerName:商家ID,customerPwd:订购申请ID");

    /**
     * 快递公司编码
     */
    private String code;

    /**
     * 开通电子面单所需字段
     */
    private String needFields;

    /**
     * key快递公司编码 value开通电子面单所需字段
     */
    private static Map<String, String> map = new HashMap<>();

    static {
        for (FaceSheetNeedField value : FaceSheetNeedField.values()) {
            try {
                map.put(value.getCode(), value.getNeedFields());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 根据快递公司获取所需字段
     *
     * @param code 快递公司编码
     * @return map key为对应数据库字段 value为开通电子面单所需字段
     */
    public static Map<String, String> getNeedFieldMap(String code) {
        String s = map.get(code);
        Map<String, String> needMap = new LinkedHashMap<>();
        if (StringUtil.isEmpty(s)) {
            return needMap;
        }
        String[] strArr = s.split(",");
        for (String str : strArr) {
            String[] split = str.split(":");
            needMap.put(split[0], split[1]);
        }
        return needMap;
    }

    /**
     * 是否包含快递公司编码
     *
     * @param code 快递公司编码
     * @return
     */
    public static Boolean isHasExpressCode(String code) {
        if (!map.containsKey(code)) {
            return false;
        }
        return true;
    }

    FaceSheetNeedField(String code, String needFields) {
        this.code = code;
        this.needFields = needFields;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getNeedFields() {
        return needFields;
    }

    public void setNeedFields(String needFields) {
        this.needFields = needFields;
    }
}
