package com.slodon.b2b2c.util;

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

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

/**
 * 快递100电子面单所需字段获取
 *
 * @author wuxy
 */
public enum FaceSheet100NeedField {

    /**
     * 电子面单所需字段
     */
    ANNENGWULIU("annengwuliu", "partnerId:安能客户编码,partnerKey:密钥"),
    DEBANGKUAIDI("debangkuaidi", "partnerId:客户编码"),
    DEBANGWULIU("debangwuliu", "partnerId:客户编码"),
    EMS("ems", "partnerId:协议客户号,partnerKey:电商客户标识,code:customerCode"),
    HUITONGKUAIDI("huitongkuaidi", "partnerId:操作编码,partnerKey:密钥"),
    BAISHIWULIU("baishiwuliu", "partnerId:账户信息,partnerKey:账户密码"),
    JD("jd", "partnerId:商家编码"),
    KUAYUE("kuayue", "partnerId:客户编码"),
    PJBEST("pjbest", "partnerId:月结账号,partnerKey:客户编码"),
    SHENTONG("shentong", "partnerId:客户名称,partnerKey:客户密码"),
    SHUNFENG("shunfeng", "partnerId:月结账号"),
    SHUNFENGKUAIYUN("shunfengkuaiyun", "partnerId:月结账号"),
    FENGWANG("fengwang", "partnerId:账户名称,partnerKey:账户密码"),
    SUER("suer", "partnerId:客户编码,net:网点编码,checkMan:取件员"),
    XINFENGWULIU("xinfengwuliu", "partnerId:客户平台ID,partnerKey:客户平台验证码,net:仓库ID"),
    YOUSHUWULIU("youshuwuliu", "partnerId:发件客户编号,partnerKey:客户校验码"),
    YOUZHENGGUONEI("youzhengguonei", "partnerId:协议客户号,partnerKey:电商客户标识"),
    YUANTONG("yuantong", "partnerId:商家代码,partnerKey:商家密钥"),
    YUANTONGGUOJI("yuantongguoji", "partnerId:商家代码,partnerKey:商家密钥"),
    YUNDA("yunda", "partnerId:合作商ID,partnerKey:密钥"),
    ZHAIJISONG("zhaijisong", "partnerId:月结账号"),
    ZHONGTONG("zhongtong", "partnerId:合作方代码,partnerKey:合作方密钥,net:网点编码"),
    ZHONGTONGKUAIYUN("zhongtongkuaiyun", "partnerId:合作方代码,partnerKey:合作方密钥"),
    EWE("ewe", "partnerId:代理店验证用户名,partnerKey:验证密码"),
    YTCHENGNUODA("ytchengnuoda", "partnerId:客户编码,partnerKey:客户密钥"),
    WEITEPAI("weitepai", "partnerId:客户编码,partnerKey:验证码"),
    LBEX("lbex", "partnerId:员工编码"),
    DSUKUAIDI("dsukuaidi", "partnerId:商家ID,partnerKey:商家密码,net:网点编码"),
    CFSS("cfss", "partnerId:项目编码"),
    JTEXPRESS("jtexpress", "partnerId:客户编码,partnerKey:客户密码"),
    HUISENKY("huisenky", "partnerId:商家编号,partnerKey:订购申请编号,partnerName:月结客户编码,checkMan:业务员编码"),
    ZHONGYOUEX("zhongyouex", "partnerId:客户编码,net:网点编号"),
    JIAYUNMEIWULIU("jiayunmeiwuliu", "partnerId:客户编号,partnerName:客户名称,net:寄件网点编号,checkMan:取件员编号"),
    IDAMALU("idamalu", "partnerId:客户编码,partnerKey:客户密码"),
    SXJDFREIGHT("sxjdfreight", "partnerId:商户ID,partnerKey:服务订购号,net:网点编号"),
    YIMIDIDA("yimidida", "partnerId:商家编号,partnerKey:订购申请编号"),
    JINGDONGKUAIYUN("jingdongkuaiyun", "partnerId:客户账户号码,code:事业部编码"),
    YUNDADIANTONGDA("yundadiantongda", "net:网点编码,checkMan:快递员编码"),
    SUTENG("suteng", "partnerId:客户编码,net:网点名称,checkMan:快递员姓名"),
    LIANHAOWULIU("lianhaowuliu", "partnerId:客户编号,checkMan:业务员编码"),
    JIAYIWULIU("jiayiwuliu", "partnerId:商家ID,partnerKey:商家密码,net:网点编号"),
    JINGUANGSUDIKUAIJIAN("jinguangsudikuaijian", "partnerId:客户编码"),
    YUNDAKUAIYUN("yundakuaiyun", "partnerId:合作商ID,partnerKey:密码"),
    TIANDIHUAYU("tiandihuayu", "partnerId:客户编号,partnerName:出发部门,code:出发部门编号"),
    CCCC58("cccc58", "partnerId:月结账号,partnerKey:秘钥"),
    NEZHASUYUN("nezhasuyun", "partnerId:客户编码"),
    SUNJEX("sunjex", "customerName:客户编码");

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

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

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

    static {
        for (FaceSheet100NeedField value : FaceSheet100NeedField.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;
    }

    FaceSheet100NeedField(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;
    }
}
