package com.tcl.ah.module.token.data;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Token {
    public static final String TOKEN_V1 ="/api/gettoken";
    public static final String TOKEN_V2 ="/api/getnewtoken";
    public static final String TOKEN =TOKEN_V2;
    public static final String PARAM_TOKEN="token";
    public static final String PARAM_TIMESTAMP="timestamp";
    public static final String PARAM_TIMEOUT="timeout";
    public static final String PARAM_SIGN="sign";
    public static final String PARAM_AAPCODE="appcode";
    @JsonProperty(PARAM_TOKEN)
    public String token="";
    @JsonProperty(PARAM_TIMESTAMP)
    public long timestamp=0;
    @JsonProperty(PARAM_TIMEOUT)
    public int timeout=0;
    public long currentTime=0 ;
    public String details="";
    @JsonProperty(PARAM_AAPCODE)
    public String appCode="";
    private String decryptAppCode="";

    public static DataWraper<Token> parseJson(String jsonStr)throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(JsonParser.Feature.ALLOW_MISSING_VALUES,true);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
        return mapper.readValue(jsonStr, new TypeReference<DataWraper<Token>>(){});
    }

    public String getDecryptAppCode() {
        return decryptAppCode;
    }

    public Token setDecryptAppCode(String decryptAppCode) {
        this.decryptAppCode = decryptAppCode;
        return this;
    }

    @Override
    public String toString() {
        return "Token{" +
                "token='" + token + '\'' +
                ", timestamp=" + timestamp +
                ", timeout=" + timeout +
                '}';
    }
}
