package com.qmth.themis.common.util;

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

import java.util.Collections;

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

    public static Result success(Object object) {
        return new Result(ExceptionResultEnum.SUCCESS.getStatusCode(), 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(BusinessException e, String message) {
        throw new BusinessException(e.getStatusCode(), e.getCode(), message);
    }

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

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

    public static Result ok(Object data) {
        return new Result(HttpStatus.HTTP_OK, data, ExceptionResultEnum.SUCCESS.getMessage());
    }

    public static Result ok(boolean success) {
        return new Result(HttpStatus.HTTP_OK, Collections.singletonMap(Constants.SUCCESS, success), ExceptionResultEnum.SUCCESS.getMessage());
    }

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

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