package com.weiqi.mis;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.common.collect.ImmutableMap;

import java.io.Serializable;
import java.util.Map;


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({"returnCode", "message", "result"})
public class ReturnValueApi<T> implements Serializable {


    @JsonProperty("returncode")
    private int returnCode;

    private String message;

    private T result;

    public int getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(int returnCode) {
        this.returnCode = returnCode;
    }

	
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public static <T> ReturnValueApi<T> buildSuccessResult(T obj) {
        ReturnValueApi<T> rt = new ReturnValueApi<>();
        rt.setReturnCode(0);
        rt.setResult(obj);
        rt.setMessage("");
        return rt;
    }

    public static ReturnValueApi buildErrorResult(int returnCode, String message) {
        ReturnValueApi rt = new ReturnValueApi();
        rt.setReturnCode(returnCode);
        rt.setMessage(message);
        return rt;
    }

    public static Map<String, Object> buildSuccessResult() {
        return ImmutableMap.of("returncode", 0, "message", "");
    }

    public static Map buildErrorMessage(int returnCode, String message) {
        return ImmutableMap.of("returncode", returnCode, "message", message);
    }

    @Override
    public String toString() {
        return "ReturnValue{" +
                "returnCode=" + returnCode +
                ", message='" + message + '\'' +
                ", result=" + result +
                '}';
    }
}
