package com.duowenlvshi.duowenlszp.app.HuaWeiPush;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;

/**
 * 华为推送intent设置
 * 配合安卓组装配合代码
 *
 * @author wangchun
 * @since 2019/7/11 10:48
 */
public class IntentHelper {

    /**
     * 推送自定义参数
     *
     * @param extraFieldMap
     * @return
     */
    public static String intent(Map<String, String> extraFieldMap) {
        String type = extraFieldMap.get("type");
        switch (type) {// type=1或者20的时候，是跳转反馈页面（FeedbackActivity）不用传参数
            case "1":
            case "20":
                return "feedback";
            case "2":// 诉保页的保险公司报价
                return "main?index=1";
            case "3":// 异地查档
                return "fadanh5?page=100&titlename=异地查档";
            case "5":// 律师信用贷首页
                return "loanscredit";
            case "6":// 一对一咨询界面
                return "queryactivity" + proceed(extraFieldMap);
            case "7":
            case "8":
            case "9":
            case "10":
            case "11":
            case "12":
                if (StringUtils.equals("1", extraFieldMap.get("orderServiceType"))) {
                    return "LGuaranteeLetterFirst" + proceed(extraFieldMap);
                }
                return "LGuaranteeProcess" + proceed(extraFieldMap);
            case "13":
                return "RedPackage";
            case "14": {
                String orderType = extraFieldMap.get("orderType");
                String appType = extraFieldMap.get("appType");
                String state = extraFieldMap.get("state");
                // orderType 1-6是异地查档订单
                String[] arr1 = {"1", "2", "3", "4", "5", "6"};
                if (Arrays.asList(arr1).contains(orderType)) {
                    if (StringUtils.equals("2", appType)) {
                        String[] stateArr = {"4", "5", "6", "7"};
                        if (Arrays.asList(stateArr).contains(state)) {
                            extraFieldMap.put("page", "100");
                            extraFieldMap.put("titlename", "异地查档");
                            return "fadanh5" + proceed(extraFieldMap);
                        }
                    }
                    return "RemoteFileWCoop" + proceed(extraFieldMap);
                }
                // 当orderType为11-16是案件合作订单
                String[] arr2 = {"11", "12", "14", "15", "16"};
                if (Arrays.asList(arr2).contains(orderType)) {
                    if (StringUtils.equals("2", appType)) {
                        String[] stateArr = {"2", "3", "4", "5", "6"};
                        if (Arrays.asList(stateArr).contains(state)) {
                            return "CoopSSuccess" + proceed(extraFieldMap);
                        }
                    }
                    String[] stateArr = {"3", "4"};
                    if (Arrays.asList(stateArr).contains(orderType)) {
                        return "CoopSSuccess" + proceed(extraFieldMap);
                    } else {
                        return "CoopSWait" + proceed(extraFieldMap);
                    }
                } else if (StringUtils.equals("13", orderType)) {
                    if (StringUtils.equals("2", appType)) {
                        extraFieldMap.put("page", "2");
                        extraFieldMap.put("titlename", "代缴费/立案");
                        return "fadanh5" + proceed(extraFieldMap);
                    }
                    String[] stateArr = {"3", "4"};
                    if (Arrays.asList(stateArr).contains(orderType)) {
                        return "CoopSSuccess" + proceed(extraFieldMap);
                    } else {
                        return "CoopSWait" + proceed(extraFieldMap);
                    }
                }
                // 当orderType都不属于上面任何一种类型的时候（跳转律师合作主页）
                return "main?index=2";
            }
            case "15": {
                String orderType = extraFieldMap.get("orderType");
                String takState = extraFieldMap.get("takState");
                String state = extraFieldMap.get("state");
                String appType = extraFieldMap.get("appType");
                // orderType 1-6是异地查档订单
                String[] arr1 = {"1", "2", "3", "4", "5", "6"};
                if (Arrays.asList(arr1).contains(orderType)) {
                    if ("2".equals(appType)) {
                        if ("0".equals(state)) {
                            extraFieldMap.put("orderType", "1");
                            extraFieldMap.put("isJd", "false");
                            extraFieldMap.put("titlename", "异地查档");
                            return "jiedanh5" + proceed(extraFieldMap);
                        } else if ("4".equals(state) || "5".equals(state) || "6".equals(state) || "7".equals(state)) {
                            extraFieldMap.put("orderType", "1");
                            extraFieldMap.put("isJd", "true");
                            extraFieldMap.put("titlename", "异地查档");
                            return "jiedanh5" + proceed(extraFieldMap);
                        }
                        extraFieldMap.put("orderType", "1");
                        extraFieldMap.put("titlename", "异地查档");
                        extraFieldMap.put("isJd", "true");
                        return "jiedanh5" + proceed(extraFieldMap);
                    }
                    if ("1".equals(takState)) {
                        String[] state_arr = {"2", "3", "4", "5", "6"};
                        if (Arrays.asList(arr1).contains(state_arr)) {
                            return "CheckFileReceive" + proceed(extraFieldMap);
                        }
                    }
                    if ("-1".equals(takState) || "0".equals(takState)) {
                        return "CoopWApply" + proceed(extraFieldMap);
                    }
                    return "main?index=2";
                }

                // 当orderType为11-16是案件合作订单
                String[] arr2 = {"11", "12", "13", "14", "15", "16"};
                if (Arrays.asList(arr2).contains(orderType)) {
                    if ("2".equals(appType)) {
                        String[] _arr1 = {"0"};
                        String[] _arr2 = {"2", "3", "4", "5"};
                        if (Arrays.asList(_arr1).contains(state)) {
                            extraFieldMap.put("orderType", "4");
                            extraFieldMap.put("titlename", "代缴诉讼费/立案");
                            extraFieldMap.put("isJd", "false");
                            return "jiedanh5" + proceed(extraFieldMap);
                        } else if (Arrays.asList(_arr2).contains(state)) {
                            extraFieldMap.put("orderType", "4");
                            extraFieldMap.put("titlename", "代缴诉讼费/立案");
                            extraFieldMap.put("isJd", "true");
                            return "jiedanh5" + proceed(extraFieldMap);
                        }
                        extraFieldMap.put("orderType", "4");
                        extraFieldMap.put("titlename", "代缴诉讼费/立案");
                        extraFieldMap.put("isJd", "true");
                        return "jiedanh5" + proceed(extraFieldMap);
                    }
                    return "CoopWApply" + proceed(extraFieldMap);
                }
                // 当orderType为21~23是纠纷订单
                String[] arr3 = {"21", "22", "23"};
                if (Arrays.asList(arr3).contains(orderType)) {
                    // 当takState=1，state=4,5,6,时
                    if ("1".equals(takState) && ("4".equals(state) || "5".equals(state) || "6".equals(state))) {
                        return "TzbLitigation" + proceed(extraFieldMap);
                    } else if ("1".equals(takState) && ("7".equals(state) || "10".equals(state) || "11".equals(state))) {
                        extraFieldMap.put("showTips", "false");
                        return "TzbLitigation" + proceed(extraFieldMap);
                    } else if ("-1".equals(takState) || "0".equals(takState)) {
                        return "TzbWCoop" + proceed(extraFieldMap);
                    }
                    // 当takState都不符合条件的时候
                    return "TzbWApply" + proceed(extraFieldMap);
                }
                // 当orderType都不符合条件的时候
                return "main?index=2";
            }
            case "16":// 首页 ok
                return "/main?index=0";
            case "17":// 律师认证页面 ok
                return "LawyerLegalize";
            case "18":// 积分提现页面 ok
                return "WithdrawalsRecord";
            case "19":// 余额提现页面 ok
                return "WithdrawalsRecord";
            case "21":// 擅长领域页面 ok
                return "PCaseAdept";
            case "22":// 我的钱包页面 ok
                return "MyWallet";
            case "23":// 保证金页面// ok
                return "shortvideo?videoJoinState=1&titlename=保证金";
            case "25":// ok
                return "SharePrize";
            // type=26，27,28,29，的时候为我的额度页面
            case "26":
            case "27":
            case "28":
            case "29":
                return "LoansMyQuota";
            case "37":
                String orderType = extraFieldMap.get("orderType");
                // orderType 1-6是异地查档订单
                String[] arr1 = {"1", "2", "3", "4", "5", "6"};
                if (Arrays.asList(arr1).contains(orderType)) {
                    extraFieldMap.put("titlename", "异地查档");
                    extraFieldMap.put("page", "100");
                    return "fadanh5" + proceed(extraFieldMap);
                }
                // 当orderType为11-16是案件合作订单
                String[] arr2 = {"11", "12", "13", "14", "15", "16"};
                if (Arrays.asList(arr2).contains(orderType)) {
                    extraFieldMap.put("titlename", "代缴诉讼费/立案");
                    extraFieldMap.put("page", "2");
                }
                return "fadanh5" + proceed(extraFieldMap);
            case "38":
                return "Recruitmentdetails?jobId="+extraFieldMap.get("jobId");
            case "39":
                return "RecruitChatActivity?titlename="+extraFieldMap.get("realName")+"&topic="+extraFieldMap.get("topic")+"&identity="+extraFieldMap.get("identityB")+"&jobId="+extraFieldMap.get("jobId")+"&lawyerIdb="+extraFieldMap.get("lawyerIdb")+"&logob="+extraFieldMap.get("logo")+"";
            default:
                return "main?index=1";
        }
    }

    /**
     * 拼装参数
     *
     * @param extraFieldMap
     * @return
     */
    protected static StringBuilder proceed(Map<String, String> extraFieldMap) {
        StringBuilder builder = new StringBuilder();
        boolean isFirst = true;
        for (Map.Entry entry : extraFieldMap.entrySet()) {
            if (isFirst) {
                isFirst = false;
                builder.append("?");
            } else {
                builder.append("&");
            }
            builder.append(entry.getKey()).append("=").append(entry.getValue());
        }
        return builder;
    }


}
