package com.qmth.jkserver.util;

import cn.hutool.http.HttpStatus;
import com.qmth.jkserver.core.SystemResult;
import com.qmth.jkserver.core.exception.JkServerException;
import com.qmth.jkserver.enums.ExceptionResultEnum;
import com.qmth.jkserver.signature.Constants;

import java.util.Collections;

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

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

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

    public static SystemResult error() {
        throw new JkServerException(ExceptionResultEnum.EXCEPTION_ERROR.getMessage());
    }

    public static SystemResult error(JkServerException e, String message) {
        throw new JkServerException(e.getCode(), message);
    }

    public static SystemResult error(String message) {
        throw new JkServerException(ExceptionResultEnum.EXCEPTION_ERROR.getCode(), message);
    }

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

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

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

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

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