package com.loan.system.utils;

import com.loan.system.domain.enums.ExceptionEnum;
import com.loan.system.domain.pojo.Result;

import java.util.HashMap;

/**
 * @author EdwinXu
 * @date 2020/9/2 - 19:53
 * @Description 响应工具类
 */
public class ResultUtil {
    private static Result result = Result.getInstance();

    public static Result success(String msg){
        return result.setCode(200).setMsg(msg).setData(null);
    }

    public static Result success(String msg, Object obj){
        return result.setCode(200).setMsg(msg).setData(obj);
    }

    public static Result success(Long total, Object obj){
        final HashMap<String, Object> map = new HashMap<>(2);
        map.put("list", obj);
        map.put("total", total);
        return result.setCode(200).setMsg("success").setData(map);
    }

    public static Result success(){
        return success("success");
    }

    public static Result error(Integer code, String msg){
        return result.setCode(code).setMsg(msg).setData(null);
    }

    public static Result error(ExceptionEnum exceptionEnum){
        return result.setCode(exceptionEnum.getCode()).setMsg(exceptionEnum.getMsg()).setData(null);
    }
    public static Result error(ExceptionEnum exceptionEnum, Object obj){
        return result.setCode(exceptionEnum.getCode()).setMsg(exceptionEnum.getMsg()).setData(obj);
    }
}
