package com.sckw.gateway.pojo;


import lombok.Data;

import java.io.Serializable;

/**
 * HTTP结果封装
 * @author zk
 * @date Oct 29, 2018
 */
@Data
public class HttpResult implements Serializable {

    private int code = HttpStatus.SUCCESS_CODE;
    private String msg = HttpStatus.SUCCESS_MESSAGE;
    private Object data;

    public static HttpResult error() {
        return error(HttpStatus.GLOBAL_EXCEPTION_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
    }

    public static HttpResult error(String msg) {
        return error(HttpStatus.GLOBAL_EXCEPTION_CODE, msg);
    }

    public static HttpResult error(int code, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static HttpResult error(String msg, Object data) {
        HttpResult r = new HttpResult();
        r.setCode(HttpStatus.GLOBAL_EXCEPTION_CODE);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static HttpResult error(int code, String msg, Object data) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }


    public static HttpResult ok() {
        return new HttpResult();
    }

    public static HttpResult ok(String msg) {
        HttpResult r = new HttpResult();
        r.setMsg(msg);
        return r;
    }

    public static HttpResult ok(Object data) {
        HttpResult r = new HttpResult();
        r.setData(data);
        return r;
    }

    public static HttpResult ok(int code, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static HttpResult ok(String msg, Object data) {
        HttpResult r = new HttpResult();
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static HttpResult ok(int code, String msg, Object data) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
}
