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({"code", "msg", "data"})
public class ReturnValuePage<T> implements Serializable {


    @JsonProperty("code")
    private int code;

    private String msg;

    private int count;

    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ReturnValuePage<T> buildSuccessdata(T obj) {
        ReturnValuePage<T> rt = new ReturnValuePage<>();
        rt.setCode(0);
        rt.setData(obj);
        rt.setMsg("");
        return rt;
    }

    public static <T> ReturnValuePage<T> buildSuccessdata(T obj,int count) {
        ReturnValuePage<T> rt = new ReturnValuePage<>();
        rt.setCode(0);
        rt.setData(obj);
        rt.setCount(count);
        rt.setMsg("");
        return rt;
    }

    public static ReturnValuePage buildErrordata(int code, String msg) {
        ReturnValuePage rt = new ReturnValuePage();
        rt.setCode(code);
        rt.setMsg(msg);
        return rt;
    }

    public static Map<String, Object> buildSuccessdata() {
        return ImmutableMap.of("code", 0, "msg", "");
    }

    public static Map buildErrormsg(int code, String msg) {
        return ImmutableMap.of("code", code, "msg", msg);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "ReturnValuePage{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", count=" + count +
                ", data=" + data +
                '}';
    }
}
