package com.sunxung.factoring.entity;

import java.io.Serializable;

/**
 * json响应数据
 */
public class ResponseJson implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 响应数据
     */
    private Object data;
    /**
     * 是否成功处理
     */
    private boolean success = true;
    /**
     * 错误信息
     */
    private Object msg;
    /**
     * 响应码
     */
    private String code = "200";


    public ResponseJson(){
    }

    public ResponseJson(Object object){
//        if (object == null) {
//            setCode("300");
//            setSuccess(false);
//            setMsg("返回结果为空");
//        } else {
            setData(object);
//        }
    }

    /**
     * 构造响应错误数据
     * 
     * @param code 错误状态吗
     * @param msg 错误信息
     */
    public ResponseJson(String code, String msg){
        setSuccess(false);
        setCode(code);
        setMsg(msg);
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

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

    public Object getMsg() {
        return msg;
    }

    public void setMsg(Object msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

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

    /**
     * 响应数据状态
     */
    public static class HttpStatus {

        /** 成功 */
        public static final int OK = 200;
        /** 未授权(没有登录) */
        public static final int UNAUTHORIZED = 401;
        /** 未找到(资源不存在) */
        public static final int NOT_FOUND = 404;
        /** 未满足前提条件(参数不正确) */
        public static final int PRECONDITION_FAILED = 412;
        /** 请求范围不符合要求(无权限) */
        public static final int NO_PERMISSION = 416;
        /** 服务器内部错误 */
        public static final int SERVER_ERROR = 500;
    }
}
