package api.common.pojo.common;

import lombok.*;

/**
 * @author martin
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseBodyVO<T> {

    // -------------------------------- Comment --------------------------------

    private boolean status;
    private int code;
    private String message;
    private T info;

    // -------------------------------- Comment --------------------------------

    /**
     *
     * @param response response 对象
     */
    public ResponseBodyVO(Response response) {
        this.status = response.isStatus();
        this.code = response.getCode();
        this.message = response.getMessage();
    }

    /**
     *
     * @param response response 对象
     * @param message message 信息
     */
    public ResponseBodyVO(Response response, String message) {
        this.status = response.isStatus();
        this.code = response.getCode();
        this.message = message;
    }

    /**
     *
     * @param response response 对象
     * @param info info 结果数据
     */
    public ResponseBodyVO(Response response, T info) {
        this.status = response.isStatus();
        this.code = response.getCode();
        this.message = response.getMessage();
        this.info = info;
    }

    public ResponseBodyVO(Response response, String message, T info) {
        this.status = response.isStatus();
        this.code = response.getCode();
        this.message = message;
        this.info = info;
    }

    /**
     * 响应信息常量类
     *
     * @author martin
     */
    @ToString
    @AllArgsConstructor(access = AccessLevel.PRIVATE)   // 枚举的构造方法默认就是 private，可以省略 access 属性。
    @Getter
    public enum Response {

        SUCCESS(true, 200, "请求成功！"),
        CLIENT_FAILURE(false, 400, "请求参数错误！"),
        SERVER_FAILURE(false, 500, "服务器错误！");

        private final boolean status;       // 成功或失败
        private final int code;             // 状态码
        private final String message;       // 信息

    }

}
