package com.red.circle.live.domain.online;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.live.domain.constant.ActiveSecondConstant;
import java.io.Serial;
import java.io.Serializable;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 房间用户.
 *
 * @author pengliang on 2023/12/8
 */
@Data
@Accessors(chain = true)
public class LiveRoomUser implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 用户id.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long userId;

  /**
   * 权重.
   */
  private Integer weights;

  /**
   * 刷新时间.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long refreshTime;

  /**
   * 更新最后一次活动时间.
   */
  public LiveRoomUser updateLastActivityTime() {
    this.refreshTime = System.currentTimeMillis();
    return this;
  }

  /**
   * 是否活跃.
   */
  public boolean checkInactiveExpire() {
    long intervalTime = (System.currentTimeMillis() - this.refreshTime) / 1000;
    return intervalTime > ActiveSecondConstant.EXPIRATION_SECOND;
  }

}
