package com.wx.application.base;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author zj
 * @description : restful 接口返回封装
 * ---------------------------------
 * @since 2017-10-27
 */
@Data
@Accessors(chain = true)
public class ResponseData<T> {
    //请求id
    private String code;
    // 状态码
    private String msg;
    //状态信息
    private T data;
    // 具体内容
    private String requestId;

    public static ResponseData SUCCESS(String msg, Object data) {
        ResponseData responseData = new ResponseData();
        responseData.msg = msg;
        responseData.data = data;
        responseData.code = ErrorCodeEnum.SUCCESS.toString();
        return responseData;
    }

    public static ResponseData ERROR(String msg, Object data) {
        ResponseData responseData = new ResponseData();
        responseData.msg = msg;
        responseData.data = data;
        responseData.code = ErrorCodeEnum.SYSTEM_ERROR.toString();
        return responseData;
    }

    public static ResponseData ERROR(ErrorCodeEnum codeEnum, String msg, Object data) {
        ResponseData responseData = new ResponseData();
        responseData.msg = msg;
        responseData.data = data;
        responseData.code = codeEnum.toString();
        return responseData;
    }

    public static ResponseData ERROR(String codeValue, String msg, Object data) {
        ResponseData responseData = new ResponseData();
        responseData.msg = msg;
        responseData.data = data;
        responseData.code = codeValue;
        return responseData;
    }

}


