package com.upload.config;

import java.io.Serializable;

public final class RestResponse<T> implements Serializable {
    private final T data;
    private final String statusCode;
    private final String message;

    private RestResponse(T data, String statusCode, String message) {
        this.data = data;
        this.statusCode = statusCode;
        this.message = message;
    }

    public static <T> RestResponse<T> success(final T data, String statusCode, String message) {
        return new RestResponse(data, statusCode, message);
    }

    public static <T> RestResponse<T> success(final T data, String message) {
        return success(data, "1", message);
    }

    public static <T> RestResponse<T> success(final T data) {
        return success(data, "1", "操作成功");
    }

    public static <T> RestResponse<T> success() {
        return success(null, "9", "暂无数据");
    }

    public static <T> RestResponse<T> fail(String statusCode, String message) {
        return new RestResponse((Object)null, statusCode, message);
    }

    public static <T> RestResponse<T> fail(String message) {
        return fail("0", message);
    }

    public static RestResponse fail() {
        return success("0", "操作失败");
    }

    public static <T> RestResponse<T> failParam() {
        return fail("0", "缺少参数或参数有误");
    }

    public static <T> RestResponse<T> exception() {
        return fail("-1", "操作发生异常");
    }

    public static <T> RestResponse<T> exception(String message) {
        return fail("-1", message);
    }

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

    public String getStatusCode() {
        return this.statusCode;
    }

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