package com.tofly.third.common.res;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Date;

@ApiModel("请求结果")
public class ResultRespone<T> implements Serializable {

    private static final long serialVersionUID = -7275852267551207696L;

    @ApiModelProperty(value = "结果代码(0:未知错误、1:成功、2:系统业务逻辑错误、3:失败、31:错误请求参数)", position = 1, example = "1")
    private Integer code;

    @ApiModelProperty(value = "结果消息", position = 2, example = "成功")
    private String message;

    @ApiModelProperty(value = "结果数据", position = 3, example = "true")
    private T result;

    @ApiModelProperty(value = "时间戳", position = 4, example = "2024-02-06 13:37:13")
    private Date timestamp = new Date();

    public ResultRespone() {
    }

    public static <T> ResultRespone<T> success() {
        return success(null, "成功");
    }

    public static <T> ResultRespone<T> success(T result) {
        return success(result, "成功");
    }

    public static <T> ResultRespone<T> failed() {
        return failed(null, "失败");
    }

    public static <T> ResultRespone<T> failed(String message) {
        return failed(null, message);
    }

    public static <T> ResultRespone<T> failed(T result) {
        return failed(result, "失败");
    }

    public static <T> ResultRespone<T> failed(T result, String message) {
        return restResult(result, 3, message);
    }

    public static <T> ResultRespone<T> success(T result, String message) {
        return restResult(result, 1, message);
    }

    private static <T> ResultRespone<T> restResult(T result, Integer code, String message) {
        ResultRespone<T> apiResult = new ResultRespone();
        apiResult.setCode(Integer.valueOf(code));
        apiResult.setResult(result);
        apiResult.setMessage(message);
        return apiResult;
    }

    public String toString() {
        return "ResultRespone(code=" + this.getCode() + ", message=" + this.getMessage() + ", result=" + this.getResult() + ")";
    }

    public Integer getCode() {
        return code;
    }

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

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

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

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

    public T getResult() {
        return this.result;
    }

    public void setResult(final T result) {
        this.result = result;
    }


}