package cn.estsh.i3plus.pojo.base.bean;

import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import io.swagger.annotations.ApiParam;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * @Description : 基本返回结果
 * @Reference :
 * @Author : alwaysfrin
 * @CreateDate : 2018-11-14 15:58
 * @Modify:
 **/
public class BaseResultBean<Obj> {

    @ApiParam("是否成功")
    public boolean success;

    @ApiParam("信息代码-国际化")
    public String code;

    @ApiParam("操作消息")
    public String msg;

    @ApiParam("错误消息")
    public String errorMsg;

    @ApiParam("http路径")
    public String url;

    @ApiParam("List结果集")
    public List<Obj> resultList;

    @ApiParam("单个结果")
    public Obj resultObject;

    @ApiParam("翻页和结果集")
    public ListPager<Obj> listPager;

    @ApiParam("Map结果集")
    public Map<String, Object> resultMap;

    @ApiParam("翻页操作")
    public Pager pager;

    @ApiParam("总记录数")
    public int totalCount;

    public boolean isSuccess() {
        return success;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public String getUrl() {
        return url;
    }

    public List<Obj> getResultList() {
        return resultList;
    }

    public Obj getResultObject() {
        return resultObject;
    }

    public ListPager<Obj> getListPager() {
        return listPager;
    }

    public Map<String, Object> getResultMap() {
        return resultMap;
    }

    public Pager getPager() {
        return pager;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public BaseResultBean setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public BaseResultBean setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
        return this;
    }

    public BaseResultBean setResultList(List<Obj> resultList) {
        this.resultList = resultList;
        return this;
    }

    public BaseResultBean setResultObject(Obj resultObject) {
        this.resultObject = resultObject;
        return this;
    }

    public BaseResultBean setListPager(ListPager<Obj> listPager) {
        this.listPager = listPager;
        return this;
    }

    public BaseResultBean setResultMap(Map<String, Object> resultMap) {
        this.resultMap = resultMap;
        return this;
    }

    public static BaseResultBean buildBaseResultBean(boolean success, String msg){
        BaseResultBean rs = new BaseResultBean();
        rs.success = success;
        if (success) {
            rs.msg = msg;
            rs.code = ResourceEnumUtil.MESSAGE.SUCCESS.getCode();
        } else {
            rs.code = ResourceEnumUtil.MESSAGE.FAIL.getCode();
            rs.errorMsg = msg;
        }

        return rs;
    }

    @Override
    public String toString() {
        return "BaseResultBean{" +
                "success=" + success +
                ", code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", url='" + url + '\'' +
                ", resultList=" + resultList +
                ", resultObject=" + resultObject +
                ", listPager=" + listPager +
                ", resultMap=" + resultMap +
                ", pager=" + pager +
                ", totalCount=" + totalCount +
                '}';
    }
}
