package com.gree.mall.manager.helper;

import cn.hutool.core.lang.TypeReference;
import com.gree.mall.manager.plus.entity.AdminField;
import io.swagger.annotations.ApiModel;

import java.util.List;

@ApiModel
public class ResponseHelper<T> {


    public static int ResponseCode_Success = 200;
    public static int ResponseCode_COMMON = 501;//通用拦截提示
    public static int ResponseCode_AUTH_ERROR = 1001;//非法请求

    private T data;
    private String message;
    private int code;
    public TypeReference<T> typeReference;

    private List<AdminField> fieldBeans;


    public static ResponseHelper success() {
        ResponseHelper object = new ResponseHelper(ResponseCode_Success, "success");
        return object;
    }

    public static ResponseHelper success(Object data) {
        ResponseHelper object = new ResponseHelper(ResponseCode_Success, "success");
        object.setData(data);
        return object;
    }

    public static ResponseHelper success(int code,Object data,String message) {
        ResponseHelper object = new ResponseHelper(ResponseCode_Success, "success");
        object.setData(data);
        object.setCode(code);
        object.setMessage(message);
        return object;
    }

    public static <T> ResponseHelper success(Object data, TypeReference<T> typeReference) {
        ResponseHelper object = new ResponseHelper(ResponseCode_Success, "success");
        object.setData(data);
        object.typeReference = typeReference;
        return object;
    }

    public static ResponseHelper error(String msg) {
        ResponseHelper object = new ResponseHelper(ResponseCode_COMMON, msg);
        return object;
    }

    public static ResponseHelper error(int code, String msg) {
        ResponseHelper object = new ResponseHelper(code, msg);
        return object;
    }


    public T getData() {
        return data;
    }

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

    public ResponseHelper(int code, String message) {
        this.code = code;
        this.message = message;
    }
    public int getCode() {
        return code;
    }

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


    public String getMessage() {
        return message;
    }

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

    public void setFieldBeans(List<AdminField> fieldBeans) {
        this.fieldBeans = fieldBeans;
    }

    public List<AdminField> getFieldBeans() {
        return this.fieldBeans;
    }

}
