package org.wcs.factory;

import org.wcs.model.vo.pub.PubServeDataResponse;
import org.wcs.model.vo.pub.PubServeResponse;

/**
 * 公用服务响应工厂类
 */
public class PubServeResponseFactory {

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

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

    /**
     * 返回一个成功的响应
     * @return 响应
     */
    public static PubServeResponse success() {
        PubServeResponse response = new PubServeResponse();
        response.setCode(200);
        response.setMessage("SUCCESS");
        return response;
    }

    /**
     * 返回一个成功的响应
     * @param msg 响应信息
     * @return 响应
     */
    public static PubServeResponse success(String msg) {
        PubServeResponse response = new PubServeResponse();
        response.setCode(200);
        response.setMessage(msg);
        return response;
    }

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

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

    /**
     * 返回一个未授权响应
     * @return 响应
     */
    public static PubServeResponse unauthorized() {
        PubServeResponse response = new PubServeResponse();
        response.setCode(401);
        response.setMessage("unauthorized");
        return response;
    }


    /**
     * 返回一个禁止访问响应
     * @return 响应
     */
    public static PubServeResponse forbidden() {
        PubServeResponse response = new PubServeResponse();
        response.setCode(403);
        response.setMessage("Forbidden");
        return response;
    }

    /**
     * 响应系统错误
     * @param msg 错误信息
     * @return 响应
     */
    public static PubServeResponse systemError(String msg) {
        PubServeResponse response = new PubServeResponse();
        response.setCode(500);
        response.setMessage(msg);
        return response;
    }

}
