package org.wcs.factory;

import org.wcs.constant.enums.serve.AppServeResponseCodeEnum;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;

/**
 * 此服务响应工厂类
 */
public class AppServeResponseFactory {

    /**
     * 返回一个普通的失败响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse fail(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.FAIL.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个带数据的失败响应
     * @param msg 响应信息
     * @param data 数据
     * @return 响应
     * @param <T> 数据范型
     */
    public static <T> AppServeDataResponse<T> fail(String msg, T data) {
        AppServeDataResponse<T> response = new AppServeDataResponse<>();
        response.setCode(AppServeResponseCodeEnum.FAIL.getCode());
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    /**
     * 返回一个成功的响应
     * @return 响应
     */
    public static AppServeResponse success() {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.SUCCESS.getCode());
        response.setMsg(AppServeResponseCodeEnum.SUCCESS.getMsg());
        return response;
    }

    /**
     * 返回一个成功的响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse success(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.SUCCESS.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个成功的响应
     * @param data 数据
     * @return 响应
     * @param <T> 数据范型
     */
    public static <T> AppServeDataResponse<T> success(T data) {
        AppServeDataResponse<T> response = new AppServeDataResponse<>();
        response.setCode(AppServeResponseCodeEnum.SUCCESS.getCode());
        response.setMsg(AppServeResponseCodeEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }

    /**
     * 返回一个成功的响应
     * @param msg 响应信息
     * @param data 数据
     * @return 响应
     * @param <T> 数据范型
     */
    public static <T> AppServeDataResponse<T> success(String msg, T data) {
        AppServeDataResponse<T> response = new AppServeDataResponse<>();
        response.setCode(AppServeResponseCodeEnum.SUCCESS.getCode());
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    /**
     * 返回一个数据重复的响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse dataRepeat(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.DATA_REPEAT.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个未授权响应
     * @return 响应
     */
    public static AppServeResponse unauthorized() {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.UNAUTHORIZED.getCode());
        response.setMsg(AppServeResponseCodeEnum.UNAUTHORIZED.getMsg());
        return response;
    }

    /**
     * 返回一个未授权响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse unauthorized(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.UNAUTHORIZED.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个带数据的未授权响应
     * @param msg 响应信息
     * @param data 数据
     * @return 结果
     * @param <T> 范型
     */
    public static <T> AppServeDataResponse<T> unauthorized(String msg, T data) {
        AppServeDataResponse<T> response = new AppServeDataResponse<>();
        response.setCode(AppServeResponseCodeEnum.UNAUTHORIZED.getCode());
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    /**
     * 返回一个禁止访问响应
     * @return 响应
     */
    public static AppServeResponse forbidden() {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.FORBIDDEN.getCode());
        response.setMsg(AppServeResponseCodeEnum.FORBIDDEN.getMsg());
        return response;
    }

    /**
     * 返回一个禁止访问响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse forbidden(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.FORBIDDEN.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个未找到响应
     * @return 响应
     */
    public static AppServeResponse notFound() {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.NOT_FOUND.getCode());
        response.setMsg(AppServeResponseCodeEnum.NOT_FOUND.getMsg());
        return response;
    }

    /**
     * 返回一个未找到响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse notFound(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.NOT_FOUND.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个服务器内部错误响应
     * @return 响应
     */
    public static AppServeResponse internalServerError() {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.INTERNAL_SERVER_ERROR.getCode());
        response.setMsg(AppServeResponseCodeEnum.INTERNAL_SERVER_ERROR.getMsg());
        return response;
    }

    /**
     * 返回一个服务器内部错误响应
     * @param msg 响应信息
     * @param data 数据
     * @return 响应信息
     * @param <T> 范型
     */
    public static <T> AppServeDataResponse<T> internalServerError(String msg, T data) {
        AppServeDataResponse<T> response = new AppServeDataResponse<>();
        response.setCode(AppServeResponseCodeEnum.INTERNAL_SERVER_ERROR.getCode());
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    /**
     * 返回一个服务器内部错误响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse internalServerError(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.INTERNAL_SERVER_ERROR.getCode());
        response.setMsg(msg);
        return response;
    }

    /**
     * 返回一个服务不可用响应
     * @return 响应
     */
    public static AppServeResponse serviceUnavailable() {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.SERVICE_UNAVAILABLE.getCode());
        response.setMsg(AppServeResponseCodeEnum.SERVICE_UNAVAILABLE.getMsg());
        return response;
    }

    /**
     * 返回一个服务不可用响应
     * @param msg 响应信息
     * @return 响应
     */
    public static AppServeResponse serviceUnavailable(String msg) {
        AppServeResponse response = new AppServeResponse();
        response.setCode(AppServeResponseCodeEnum.SERVICE_UNAVAILABLE.getCode());
        response.setMsg(msg);
        return response;
    }




}
