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

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
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
@JsonIgnoreProperties(ignoreUnknown = true)
@Accessors(chain = true)
public class LiveMicrophone implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 麦克风位置索引 从0开始.
   */
  private Integer micIndex;

  /**
   * 麦克风用户.
   */
  private LiveMicUser user;

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

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

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

}
