package com.qmth.themis.common.util;

import cn.hutool.http.HttpStatus;
import com.qmth.themis.common.enums.ExceptionResultEnum;
import com.qmth.themis.common.exception.BusinessException;

/**
 * @Description: 自定义消息工具
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2019/10/11
 */
public class ResultUtil {

    public static Result success(Object object) {
        return new Result(ExceptionResultEnum.SUCCESS.getCode(), ExceptionResultEnum.SUCCESS.getMessage(), object);
    }

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

    public static Result error(int code, String message) {
        return new Result(code, message);
    }

    public static Result error() {
        throw new BusinessException(ExceptionResultEnum.EXCEPTION_ERROR);
    }

    public static Result error(String message) {
        throw new BusinessException(ExceptionResultEnum.ERROR.getStatusCode(), ExceptionResultEnum.ERROR.getCode(), message);
    }

    public static Result ok(String message) {
        return new Result(HttpStatus.HTTP_OK, message);
    }

    public static Result ok(Object data) {
        Result r = new Result();
        r.setCode(HttpStatus.HTTP_OK);
        r.setData(data);
        r.setMessage(ExceptionResultEnum.SUCCESS.getMessage());
        return r;
    }

    public static Result ok(Object data, String message) {
        Result r = new Result();
        r.setCode(HttpStatus.HTTP_OK);
        r.setData(data);
        r.setMessage(message);
        return r;
    }

    public static Result ok() {
        Result r = new Result();
        r.setCode(HttpStatus.HTTP_OK);
        return r;
    }
}
