package com.qmth.file.core;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class Token {

    private String mac;

    private String examCode;

    private long createTime;
    
    private String random;

    private Token() {

    }


    public static String serialize(String mac, String examCode, long createTime,String random)
            throws JsonProcessingException {
        Token token = new Token();
        token.setMac(mac);
        token.setExamCode(examCode);
        token.setCreateTime(createTime);
        token.setRandom(random);
        ObjectMapper mapper = new ObjectMapper();
        return AesEncryptUtil.encrypt(mapper.writeValueAsString(token));
    }

    public static Token deserialize(String text) throws JsonParseException, JsonMappingException, IOException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(AesEncryptUtil.decrypt(text), Token.class);
    }

	public String getRandom() {
		return random;
	}


	public void setRandom(String random) {
		this.random = random;
	}


	/**
	 * @return the mac
	 */
	public String getMac() {
		return mac;
	}


	/**
	 * @param mac the mac to set
	 */
	public void setMac(String mac) {
		this.mac = mac;
	}


	/**
	 * @return the examCode
	 */
	public String getExamCode() {
		return examCode;
	}


	/**
	 * @param examCode the examCode to set
	 */
	public void setExamCode(String examCode) {
		this.examCode = examCode;
	}


	/**
	 * @return the createTime
	 */
	public long getCreateTime() {
		return createTime;
	}


	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

    

}
