package com.iformall.common;

import java.util.HashMap;

/**
 * @author chenkx
 * @date 2018-01-05.
 */
public class InvestResultData<T> extends Result {

    public T data;

    public InvestResultData() {
        super();
    }

    public InvestResultData(T data) {
        this();
        this.data = data;
    }


    public static InvestResultData returnResultObject(int code) {
        String value = ErrorCode.getByCode(code).getMessage();
        return new InvestResultData(code, value);
    }

    public InvestResultData(int code, Exception e) {
        super(code, e.toString());
    }


    public InvestResultData(int code, String message) {
        super(code, message);
    }

    public InvestResultData(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public InvestResultData(ErrorCode errorCode, T data) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
        this.data = data;
    }

    public InvestResultData(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
    }

    public HashMap<String, Object> toHashMap() {
        HashMap<String, Object> map = new HashMap<>(3);
        map.put("code", this.code);
        map.put("message", this.message);
        map.put("data", data);
        return map;
    }

}
