/*
 * *************************************************
 * Copyright (c) 2018 QMTH. All Rights Reserved.
 * Created by Deason on 2018-07-12 15:31:10.
 * *************************************************
 */

package cn.com.qmth.examcloud.core.questions.base.converter.model;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success;//是否成功
    private String message;//描述信息
    private T data;//结果数据

    public Result() {

    }

    public Result(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功结果
     */
    public Result success(T data) {
        this.success = true;
        this.data = data;
        return this;
    }

    public Result success() {
        this.success = true;
        return this;
    }

    /**
     * 错误结果
     */
    public Result error(String message) {
        this.success = false;
        this.message = message;
        return this;
    }

    public Result error() {
        this.success = false;
        return this;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    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;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }

}