/// 心跳配置
class PresenceConfig {
  final int heartbeatIntervalSeconds;
  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,
    );
  }
}
