package com.imdroid.beidou.common;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class HttpResult implements Serializable {
    public static int HTTP_RSP_OK = 0;
    public static int HTTP_RSP_FAILED = 1;
    public static int HTTP_RSP_USER_NOT_EXIST = 2;
    int code;
    String msg;
    Object data;

    public static String result(int code, String msg) {
        HttpResult rsp = new HttpResult();
        rsp.code = code;
        rsp.msg = msg;
        return JSONObject.toJSONString(rsp);
    }

    public static String ok() {
        return result(HTTP_RSP_OK, "ok");
    }

    public static String failed() {
        return result(HTTP_RSP_FAILED, "failed");
    }

    public static HttpResult success(Object data) {
        return new HttpResult(HTTP_RSP_OK, "ok", data);
    }

    public static HttpResult fail(String msg) {
        return new HttpResult(HTTP_RSP_FAILED, msg, null);
    }

    public static HttpResult fail(int code, String msg) {
        return new HttpResult(code, msg, null);
    }
}
