package com.fzm.mall.server.front.repo;

import com.fzm.mall.server.front.base.ResponseVO;
import com.fzm.mall.server.front.constant.MallResponseEnum;
import org.springframework.stereotype.Component;

/**
 * @author wangp
 * @date 2021/3/1 15:18
 * @description 返回工厂
 * @since JDK 1.8
 */
@Component
public class ResponseFactory {

    public ResponseVO<String> getSimpleSuccessResponse() {
        return new ResponseVO<>(MallResponseEnum.SUCCESS);
    }

    public ResponseVO<String> getSimpleFailureResponse() {
        return new ResponseVO<>(MallResponseEnum.FAIL);
    }

    public ResponseVO<String> getResponse(String code) {
        return new ResponseVO<>(code);
    }

    public <T> ResponseVO<T> getSuccessResponseWithData(T data) {
        return new ResponseVO<>(MallResponseEnum.SUCCESS, data);
    }

    public <T> ResponseVO<T> getFailResponseWithData(T data) {
        return new ResponseVO<>(MallResponseEnum.FAIL, data);
    }

    public <T> ResponseVO<T> getResponseWithData(String code, T data) {
        return new ResponseVO<>(code, data);
    }
}
