handleCommand static method

Future<void> handleCommand(
  1. BuildContext context,
  2. Map<String, dynamic> data
)

Implementation

static Future<void> handleCommand(
    BuildContext context, Map<String, dynamic> data) async {
  final String? type = data['type'];
  log("🎮 Remote Command Received-->: $type | Data: $data");

  if (type == null) return;

  final uiProvider = Provider.of<TryOnDataUiProvider>(context, listen: false);
  final productProvider =
      Provider.of<ProductDataProvider>(context, listen: false);
  final wishlistProvider =
      Provider.of<WishlistProvider>(context, listen: false);

  switch (type) {
    case 'augment':
      await _handleAugment(context, uiProvider, data);
      break;

    case 'category':
      final String? category = data['category'];
      if (category != null) {
        productProvider.setSelectedCategory = category;
        productProvider.updateLoadingState = true;
        await productProvider.getProductList();
        Future.delayed(const Duration(milliseconds: 100), () {
          productProvider.updateLoadingState = false;
        });
      }
      break;

    case 'subCategory':
      final String? category = data['category'];
      if (category != null) {
        productProvider.setSelectedTryonType = category;
        productProvider.updateLoadingState = true;
        await productProvider.getProductList(tryonType: category);
        Future.delayed(const Duration(milliseconds: 100), () {
          productProvider.updateLoadingState = false;
        });
      }
      break;

    case 'fullscreen':
      final bool? value = data['value'];

      if (value != null) {
        uiProvider.setKioskFullScreen = value;
      }
      break;

    case 'lookbook':
      final bool? value = data['value'];
      if (value != null) {
        uiProvider.setKioskBottomPanel = value ? 1 : 0;
      }
      break;

    case 'get_lookbook':
      _handleGetLookbook(context);
      break;

    case 'lookbook_collection':
      final String? collectionId = data['collectionId'];
      if (collectionId != null) {
        final lookbookProvider =
            Provider.of<LookbookProvider>(context, listen: false);
        lookbookProvider.selectedCollectionId = collectionId;
      }
      break;

    case 'user_id_sync':
      final userId =
          (data['user_id'] ?? data['userId'] ?? '').toString().trim();
      uiProvider.syncUserId(userId);
      if (userId.isNotEmpty) {
        await wishlistProvider.getWishlist();
      }
      break;

    case 'capture':
      final String? mode = data['mode']; // 'photo' or 'video'
      final String? action = data['action']; // 'start' or 'stop'
      if (mode == 'photo') {
        await uiProvider.captureNew();
      } else if (mode == 'video') {
        if (action == 'start') {
          uiProvider.captureVideo();
        } else {
          await uiProvider.stopVideo();
        }
      }
      break;

    case 'feed_control':
      // WishlistProvider? wishlistProviderData =   wishlistProvider;
      _handleFeedControl(uiProvider, data, wishlistProvider);
      break;

    case 'adjustment':
      _handleAdjustment(uiProvider, data);
      break;
    case 'theme':
      final bool? isDark = data['isDark'];
      if (isDark != null) {
        // implement your theme provider logic
        log("🎨 Theme change: $isDark");
      }
      break;

    case 'tryon_mode':
      await _handleTryonMode(uiProvider, productProvider, data);
      break;

    case 'upload_image':
      uiProvider.openGallery();
      break;

    case 'open_camera':
      uiProvider.openCamera();
      break;

    case 'close_camera':
      uiProvider.closeCamera();
      break;

    case 'open_info':
      await _ensureKioskPanelVisible(uiProvider);
      uiProvider.setKioskRightPanel = 2;
      break;
    case 'open_gallery':
      await _ensureKioskPanelVisible(uiProvider);
      uiProvider.setKioskRightPanel = 4;
      break;
    case 'close_info':
      uiProvider.setKioskRightPanel = 0;
      break;
    case 'open_product_detail':
      final String? productId = data['productId'];
      if (productId != null) {
        await _ensureKioskPanelVisible(uiProvider);
        // Fetch the full product details
        final detailsProvider = Provider.of<TryOnProductDetailsProvider>(
          context,
          listen: false,
        );
        final ApiResponse response = await detailsProvider
            .getDetailsByIdForTryon(productId, fromId: true);

        if (response.status && response.data != null) {
          final product = ProductModel.fromJson(
            jsonDecode(jsonEncode(response.data)),
          );
          // Set this product as the active one so the panel shows it
          uiProvider.setActiveFromStack(product);
        }
        // Open the info panel — it now shows the product we just set active
        uiProvider.setKioskRightPanel = 2;
      }
      break;

//handleCompareMode(false, 0);
    case 'open_info_3d':
      await _ensureKioskPanelVisible(uiProvider);
      final product = uiProvider.currentlyAugmenting;

      if (product != null && product.object3d != null) {
        uiProvider.setThreeUrl = product.url3d!;
        uiProvider.setKioskRightPanel = 5;
      } else {
        log("❌ No 3D available for current product");
      }
      break;

    case 'open_wishlist':
      await _ensureKioskPanelVisible(uiProvider);
      if (URLConstants.user_id.isNotEmpty) {
        uiProvider.setKioskRightPanel = 1;
      } else {
        uiProvider.setKioskRightPanel = 3;
      }
      break;

    case 'model_image':
      final String? identifier = data['identifier'];
      final String? imageUrl = data['imageUrl'];

      if (identifier != null && imageUrl != null) {
        productProvider.setSelectedModelImageIdentifier(identifier);

        uiProvider.changeModelImage(imageUrl);
      }
      break;

    case 'ai_visualize_result':
      await _handleAiVisualizeResult(context, data);
      break;

    case 'ai_create_look':
      RemoteAiCreateLookPopup.handle(context, data);
      break;

    case 'pointer':
      _handlePointer(context, data);
      break;

    case 'keyboard':
      _handleKeyboard(context, data);
      break;

    default:
      log("⚠️ Unknown remote command type: $type");
  }
}