package com.tax.token.model;

import com.alibaba.fastjson.JSON;
import com.yxcheng.token.common.model.TaxUserInfo;
import com.yxcheng.token.utils.StringUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
public class TkToken {

    private Integer id;

    private String taxno;

    private String token;

    private String tokenStatus;

    private Date reqDate;

    private Date resDate;

    private String keyCode;

    private String secert;

    private String zoneCode;

    private String userCode;

    private String serverNo;

    private Integer times;

    private String isValid;

    private String ipServerNo;

    private String tokenMessage;

    private String tokenCode;

    private String userType;

    private String tokenErrorMessage;

    private String tokenErrorCode;

    private Date tokenErrorDate;

    private String secretMd5;

    private String requestFrom;

    private String errorCode;

    private String errorMessage;

    private String zoneFlag = "0";

    private String loginType;

    private String functionNo;

    private Date retryTime;

    private String retrySecond;

    private Date createDate;

    private Date updateDate;

    private boolean jsonFlag = false;
    private TaxUserInfo taxUserInfo;

    private String proxyIp;

    private String taxLoginName;

    private String requestId;

    private String updateErrorFlag;

    private String resContext;

    private String checkType;

    private String site;

    private String target;

    @Override
    public String toString() {
        return "TkToken{" +
                "taxno='" + taxno + '\'' +
                ", zoneCode='" + zoneCode + '\'' +
                ", token='" + token + '\'' +
                ", tokenStatus='" + tokenStatus + '\'' +
                ", tokenMessage='" + tokenMessage + '\'' +
                ", tokenCode='" + tokenCode + '\'' +
                ", userType='" + userType + '\'' +
                ", requestFrom='" + requestFrom + '\'' +
                ", isValid='" + isValid + '\'' +
                ", errorCode='" + errorCode + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                '}';
    }

    public TaxUserInfo parseTaxUserInfo() {
        if(StringUtil.isNotEmpty(getSecert()) && StringUtil.isJSON(getSecert())) {
            taxUserInfo = JSON.parseObject(getSecert(), TaxUserInfo.class);
        }
        return taxUserInfo;
    }

    public String printSaveInfo() {
        return getTaxno() + ",userCode:" + getUserCode()  + ",secert:" + getSecert() + ",userType:" + getUserType() + ",jsonFlag:" + isJsonFlag() + ",isValid:" + getIsValid();
    }
}