/// 心跳配置
class PresenceConfig {
  /// 心跳间隔（秒）
  /// 默认 60 秒，与后端 3 分钟窗口配合
  final int heartbeatIntervalSeconds;

  /// 是否仅登录用户发送心跳
  /// 默认 true，未登录用户不参与在线统计
  final bool requiresAuth;

  /// 是否启用心跳
  final bool enabled;

  const PresenceConfig({
    this.heartbeatIntervalSeconds = 60,
    this.requiresAuth = true,
    this.enabled = true,
  });

  /// 默认配置
  static const PresenceConfig defaultConfig = PresenceConfig();

  /// 从远程配置解析
  factory PresenceConfig.fromJson(Map<String, dynamic> json) {
    return PresenceConfig(
      heartbeatIntervalSeconds: json['heartbeat_interval_seconds'] ?? 60,
      requiresAuth: json['requires_auth'] ?? true,
      enabled: json['presence_enabled'] ?? json['enabled'] ?? true,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'heartbeat_interval_seconds': heartbeatIntervalSeconds,
      'requires_auth': requiresAuth,
      'presence_enabled': enabled,
    };
  }

  PresenceConfig copyWith({
    int? heartbeatIntervalSeconds,
    bool? requiresAuth,
    bool? enabled,
  }) {
    return PresenceConfig(
      heartbeatIntervalSeconds:
          heartbeatIntervalSeconds ?? this.heartbeatIntervalSeconds,
      requiresAuth: requiresAuth ?? this.requiresAuth,
      enabled: enabled ?? this.enabled,
    );
  }
}
