package com.chaozhanggui.common.system.config;

import com.chaozhanggui.common.system.util.ExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

//命名区别于ResponseBody注解
public class RespBody {

    public static String  fail="400";
    private static Logger logger = LoggerFactory.getLogger(RespBody.class);
    private String code;
    private String message;
    private Object data;

    public RespBody() {//Integer不会走这里
        setCode("000000");
        setMessage(ExceptionUtil.map.get(code));
    }

    public RespBody(Exception e) {
        if(e.getMessage().substring(0,1).equals("!")){
            setMessage(e.getMessage(),"-60009");
        }else {
            try {
                setCode(e.getMessage());
            } catch (NumberFormatException e1) {
                setMessage(e.getMessage(),"-1");
                logger.info("", e);
            }
        }
    }

    public  RespBody(Object data) {
        setCode("000000");
        this.data = data;
    }

    public RespBody(String code,Object data){
        this.code=code;
        this.data=data;
        setMessage(ExceptionUtil.map.get(code));
    }

    public RespBody(String code,String message){
        this.code=code;
        this.message=message;
    }

    public RespBody(String code){
        this.code=code;
        setMessage(ExceptionUtil.map.get(code));
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
        setMessage(ExceptionUtil.map.get(code));
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setMessage(String message,String code) {
        this.message = message;
        this.code=code;
    }

    public Object getData() {
        return data;
    }

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