package com.huatek.busi.common.util;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;
import com.huatek.torch.util.tools.HuatekTools;

/**
 * 工具类
 * 
 * @author anker_cheng
 * @date 2019/08/26
 * @see com.huatek.torch.frame.tools.ResultUtil
 */
public final class BusiResultUtil {
    public BusiResultUtil() {}

    public static Map<String, Object> put(int code, String msg, Object data) {
        Map<String, Object> resultMap = Maps.newLinkedHashMapWithExpectedSize(4);
        resultMap.put("code", Integer.valueOf(code));
        resultMap.put("msg", message(msg));
        resultMap.put("token", "");
        resultMap.put("data", data);
        return resultMap;
    }

    public static Map<String, Object> put(int code, String msg, Object data, String token) {
        Map<String, Object> resultMap = Maps.newLinkedHashMapWithExpectedSize(4);
        resultMap.put("code", Integer.valueOf(code));
        resultMap.put("msg", message(msg));
        resultMap.put("token", token);
        resultMap.put("data", data);
        return resultMap;
    }

    public static Map<String, Object> put(int code, long count, String msg, Object data) {
        Map<String, Object> resultMap = Maps.newLinkedHashMapWithExpectedSize(5);
        resultMap.put("code", Integer.valueOf(code));
        resultMap.put("count", Long.valueOf(count));
        resultMap.put("msg", message(msg));
        resultMap.put("token", "");
        resultMap.put("data", data);
        return resultMap;
    }

    private static String message(String msg) {
        String message = HuatekTools.message(msg);
        return StringUtils.isEmpty(message) ? msg : message;
    }
}
