enum BridgeCommand {
  haptic,
  share,
  audio,
  navSync,
  authReady,
  authLogout,
  badge,
  cacheProfile,
  cacheMatch,
  requestContacts,
  requestCamera,
}

class BridgeMessage {
  final BridgeCommand command;
  final Map<String, dynamic> data;

  BridgeMessage({required this.command, this.data = const {}});

  factory BridgeMessage.fromJson(Map<String, dynamic> json) {
    final cmd = _parseCommand(json['cmd'] as String? ?? '');
    final data = Map<String, dynamic>.from(json)..remove('cmd');
    return BridgeMessage(command: cmd, data: data);
  }

  static BridgeCommand _parseCommand(String cmd) {
    switch (cmd) {
      case 'haptic':
        return BridgeCommand.haptic;
      case 'share':
        return BridgeCommand.share;
      case 'audio':
        return BridgeCommand.audio;
      case 'nav_sync':
        return BridgeCommand.navSync;
      case 'auth_ready':
        return BridgeCommand.authReady;
      case 'auth_logout':
        return BridgeCommand.authLogout;
      case 'badge':
        return BridgeCommand.badge;
      case 'cache_profile':
        return BridgeCommand.cacheProfile;
      case 'cache_match':
        return BridgeCommand.cacheMatch;
      case 'request_contacts':
        return BridgeCommand.requestContacts;
      case 'request_camera':
        return BridgeCommand.requestCamera;
      default:
        return BridgeCommand.haptic;
    }
  }
}
