package com.ematou.wxservice.common.web;

import com.ematou.wxservice.common.constant.ResponseCodeConstant;

/**
 * @author lhm
 * @version 1.0
 * 2021-04-30 14:25
 */
public class R<T> {

    private int code;

    private String message;

    private T data;

    public R() {
    }

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

    public R<T> success(T data) {
        this.setCode(ResponseCodeConstant.code_Success);
        this.setMessage("success");
        this.setData(data);
        return this;
    }

    public R<T> success() {
        this.setCode(ResponseCodeConstant.code_Success);
        this.setMessage("success");
        this.setData(null);
        return this;
    }

    public R<T> error(String message) {
        this.setCode(ResponseCodeConstant.code_100);
        this.setMessage(message);
        this.setData(null);
        return this;
    }

    public int getCode() {
        return code;
    }

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

    public String getMessage() {
        return message;
    }

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

    public T getData() {
        return data;
    }

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