package com.gic.haoban.manage.web.controller;

import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;

/**
 * Created 2018/7/18.
 *
 * @author hua
 */
public class WebBaseController {

    protected final String defaultReturn = "json";

    public HaobanResponse resultResponse(HaoBanErrCode errCode, Object data, String detailError) {
        HaobanResponse response = new HaobanResponse();
        response.setMessage(errCode.getMsg());
        response.setErrorCode(errCode.getCode());
        response.setResult(data);
        response.setDetailError(detailError);
        return response;
    }

    public HaobanResponse resultResponse(HaoBanErrCode errCode, Object data) {
        return resultResponse(errCode, data, null);
    }

    public HaobanResponse resultResponse(HaoBanErrCode errCode) {
        return resultResponse(errCode, null, null);
    }
    
    public HaobanResponse resultResponse(HaoBanErrCode errCode, String message,Object data,String detailError) {
        HaobanResponse response = new HaobanResponse();
        response.setMessage(message);
        response.setDetailError(detailError);
        response.setErrorCode(errCode.getCode());
        return response;
    }
    
    public HaobanResponse success(Object obj) {
        return resultResponse(HaoBanErrCode.ERR_1, obj, null);
    }

    public HaobanResponse fail(String message) {
        HaobanResponse response = new HaobanResponse();
        response.setMessage(message);
        response.setErrorCode(HaoBanErrCode.ERR_OTHER.getCode());
        response.setDetailError(message);
        return response;
    }
}
