package com.jeequan.jeepay.member.secruity;

import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.utils.DateKit;
import lombok.Data;

import java.util.Map;

/**
 * JWT payload 载体
 * 格式：
 * {
 * "mbrId": "10001",
 * "created": "1568250147846",
 * "cacheKey": "KEYKEYKEYKEY",
 * }
 *
 * @author terrfly
 * @date 2021/6/8 18:01
 */
@Data
public class JWTPayload {

    private String mbrId;       //登录会员ID
    private Long created;         //创建时间, 格式：13位时间戳
    private String cacheKey;      //redis保存的key

    protected JWTPayload() {
    }

    public JWTPayload(JeeMemberDetails jeeMemberDetails) {

        this.setMbrId(jeeMemberDetails.getMemberInfo().getMbrId());
        this.setCreated(DateKit.currentTimeMillis());
        this.setCacheKey(jeeMemberDetails.getCacheKey());

    }

    /**
     * toMap
     **/
    public Map<String, Object> toMap() {
        JSONObject json = (JSONObject) JSONObject.toJSON(this);
        return json.toJavaObject(Map.class);
    }

}
