package com.community.commom.mode;

import java.io.Serializable;

/**
 * 接口统一状态返回BEAN.
 */
public class ResponseBean<T> implements Serializable {

    private static final long serialVersionUID = 3593827217136880822L;

    public static final String CODE_SUCCESS =  "0";
    public static final String CODE_FAIL =  "1";

    private String code = "0";

    private String message = "成功";

    private T data;

    private String url;

    public ResponseBean() {
    }

    public void addDefaultError() {
        this.code = "1";
        this.message = "失败";
    }

    public void addError(String message) {
        this.code = "1";
        this.message = message;
    }

    public void addError(String message, String url) {
        this.code = "1";
        this.message = message;
        this.url = url;
    }

    public void addError(String message, T data, String url) {
        this.code = "1";
        this.message = message;
        this.url = url;
        this.data = data;
    }

    public void addSuccess(String message) {
        this.code = "0";
        this.message = message;
    }

    public void addSuccess(String code, T data) {
        this.code = code;
        this.message = "成功";
        this.data = data;
    }

    public void addSuccess(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public void addSuccess(String message, T data, String url) {
        this.code = "0";
        this.message = message;
        this.data = data;
        this.url = url;
    }

    public void addSuccess(T data) {
        this.code = "0";
        this.message = "成功";
        this.data = data;
    }

    public T getData() {
        return this.data;
    }

    public String getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    @Override
    public String toString() {
        return "ResponseBaseBean [code=" + this.code + ", message=" + this.message + ", data=" + this.data + ", url=" + url + "]";
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}
