package com.brilliance.isc.vo;

import com.brilliance.isc.warn.impl.WarnServiceImpl;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;

import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResponseSet<T> {

    /**
     * 成功代码
     */
    public static final String CODE_SUCCESS="AAAAAA";
    public static final String MSG_SUCESS="操作成功！";

    /**
     * 错误码
     */
    private String respCode;
    /**
     * 错误信息
     */
    private String respMsg;
    /**
     * 字段错误信息
     */
    @Deprecated
    private Map<String,String> fieldErrors;
    /**
     * 返回码表
     */
    @Deprecated
    private Map<String, List<String>> codeSet;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 警告列表
     */
    private List<WarnVo> warnList;

    public ResponseSet(){
    }

    public ResponseSet(T t){
        this.respCode = CODE_SUCCESS;
        this.respMsg = MSG_SUCESS;
        this.data = t;
        this.warnList = WarnServiceImpl.directGetAndClearTotalWarns();
    }

    public ResponseSet(String errCode,String errMsg){
        this.respCode = errCode;
        this.respMsg = errMsg;
        this.warnList = WarnServiceImpl.directGetAndClearTotalWarns();
    }

    public ResponseSet(String errCode,String errMsg,T t){
        this(errCode,errMsg);
        this.data = t;
        this.warnList = WarnServiceImpl.directGetAndClearTotalWarns();
    }
    public Object getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }

    public String getRespCode() {
        return respCode;
    }

    public void setRespCode(String respCode) {
        this.respCode = respCode;
    }

    public String getRespMsg() {
        return respMsg;
    }

    public void setRespMsg(String respMsg) {
        this.respMsg = respMsg;
    }

    public Map<String, String> getFieldErrors() {
        return fieldErrors;
    }

    public void setFieldErrors(Map<String, String> fieldErrors) {
        this.fieldErrors = fieldErrors;
    }

    public Map<String, List<String>> getCodeSet() {
        return codeSet;
    }

    public void setCodeSet(Map<String, List<String>> codeSet) {
        this.codeSet = codeSet;
    }

    public List<WarnVo> getWarnList(){
        return this.warnList;
    }

    static class BooleanResult{
        boolean result;
        public BooleanResult(boolean result){
            this.result = result;
        }
    }
    static final String FAIL_CODE = "999999";
    public static ResponseSet fail(String message) {
        ResponseSet responseSet = new ResponseSet(FAIL_CODE,message);
        return responseSet;
    }
    public static ResponseSet simpleSuccess(Object data){
        return new ResponseSet(data);
    }

}
