package com.bonus.sgzb.auth.form;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author caoxianfei
 * @Version 1.0
 * @date 2021-08-13 10:07
 */
public class RespLoginData<T> {

    protected String code;
    protected String message;
    protected String msg;
    protected String status;
    protected Boolean success;
    protected List<T> dataList;
    protected T data;

    public RespLoginData(){
    }

    public RespLoginData(String str, Class<T> clazz) {
        if (StringUtils.isNotBlank(str)) {
            JSONObject json = JSON.parseObject(str);
            this.code = json.getString("code");
            this.message = json.getString("message");
            this.status = json.getString("status");
            this.msg = json.getString("msg");
            this.success = Boolean.parseBoolean(json.getString("success"));
            if (null != clazz) {
                if (json.get("data") != null && StringUtils.isNotBlank(json.getString("data"))) {
                    try{
                        this.data = JSONObject.parseObject(json.getString("data"), clazz);
                    } catch (Exception e) {

                        try {
                            this.dataList = JSONObject.parseArray(json.getString("data"), clazz);
                        } catch (Exception ex) {
                            this.data = null;
                        }
                    }
                }
            } else {
                /* this.data = (T)JSONObject.parseObject(json.getString("data"), Boolean.class);*/
                this.data = null;
            }
        }
    }

    public RespLoginData(String code, String message, String msg, String status, Boolean success, T data, List<T> dataList) {
        this.code = code;
        this.message = message;
        this.msg = msg;
        this.status = status;
        this.success = success;
        this.data = data;
        this.dataList = dataList;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
