package cn.freemud.management.util;

import cn.freemud.base.constant.Version;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.management.enums.ResponseResult;

/**
 * @title: ResponseUtil
 * @package: cn.freemud.utils
 * @author: jiale<loverichy8 @ gmail.com>
 * @date: 2017/11/29
 * @description:
 */
public class ResponseUtil {

    /**
     * @param <T>
     * @return
     */
    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>(Version.VERSION_1, ResponseResult.SUCCESS.getCode(),"success");
    }

    /**
     * @param t
     * @param <T>
     * @return
     */
    public static <T> BaseResponse<T> success(T t) {
        return new BaseResponse<>(ResponseResult.SUCCESS.getCode(), "success", Version.VERSION_1, t);
    }

    public static <T> BaseResponse<T> error(ResponseResult status) {
        return new BaseResponse<>(Version.VERSION_1, status.getCode(), status.getMessage());
    }

    /**
     * @param code
     * @return
     */
    public static <T> BaseResponse<T> error(String code) {
        return new BaseResponse<>(Version.VERSION_1, code);
    }

    /**
     * @param code
     * @param message
     * @return
     */
    public static <T> BaseResponse<T> error(String code, String message) {
        return new BaseResponse<>(Version.VERSION_1, code, message);
    }

    public static <T> BaseResponse<T> error(String code, String message, T t) {
        return new BaseResponse<>(code, message, Version.VERSION_1, t);
    }

    public static <T> BaseResponse<T> error(ResponseResult status, T t) {
        return new BaseResponse<>(status.getCode(), status.getMessage(), Version.VERSION_1, t);
    }

}
