package com.ywt.core;

/**
 * Created by dyh2020
 */
public class DataResponse<T> extends BaseResponse {
    private T data;


    public T getData() {
        return data;
    }

    public DataResponse<T> setData(T data) {
        this.data = data;
        return this;
    }

    public DataResponse<T> failed(int code, String info){
        this.code = code;
        this.info = info;
        return this;
    }


    public DataResponse<T> error(String info) {
        this.code = BaseResponse.APP_EXCEPTION;
        this.info = info;
        return this;
    }

    public DataResponse<T> succeed(String info){
        this.code = BaseResponse.SUCCEED;
        this.info = info;
        return this;
    }

    public DataResponse<T> succeed(T data){
        this.code = BaseResponse.SUCCEED;
        this.info = "操作成功";
        this.data = data;
        return this;
    }

    public DataResponse<T> succeed(String info, T data) {
        this.code = BaseResponse.SUCCEED;
        this.info = info;
        this.data = data;
        return this;
    }


    public DataResponse<T> failedWithParameterError(){
        this.code = BaseResponse.PARAMETER_ERROR;
        this.info = "参数错误";
        return this;
    }

    @Override
    public DataResponse<T> failedWithParameterError(String info){
        this.code = BaseResponse.PARAMETER_ERROR;
        this.info = info;
        return this;
    }

    public DataResponse<T> failedWithAppError(){
        this.code = BaseResponse.APP_ERROR;
        this.info = "处理失败";
        return this;
    }

    public DataResponse<T> failedWithAppError(String info){
        this.code = BaseResponse.APP_ERROR;
        this.info = info;
        return this;
    }
    public DataResponse<T> error() {
        this.code = BaseResponse.APP_EXCEPTION;
        this.info = "系统开小差，请稍后重试";
        return this;
    }


}
