package com.ssyf.ws.domain;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 会话信息实体
 * 存储用户连接会话的相关信息
 */
@Data
@Accessors(chain = true)
public class SessionInfo {
    
    // 用户ID
    private String userId;
    
    // 用户名
    private String username;
    
    // 会话ID
    private String sessionId;
    
    // 登录时间
    private Long loginTime;
    
    // 最后活跃时间
    private Long lastActiveTime;
    
    // 客户端信息
    private String clientInfo;

    private String masterAccountId;

    private String fansId;
    
    // 扩展属性
    private Map<String, Object> attributes;
    
    public SessionInfo() {
        this.attributes = new ConcurrentHashMap<>();
        this.loginTime = new Date().getTime();
        this.lastActiveTime = new Date().getTime();
    }
    
    public SessionInfo(String userId, String username, String sessionId) {
        this();
        this.userId = userId;
        this.username = username;
        this.sessionId = sessionId;
    }

    public void updateLastActiveTime() {
        this.lastActiveTime = new Date().getTime();
    }
}