package dev.jasonpearson.automobile.playground.navigation

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log

/**
 * Utility class for managing deep link URLs within the AutoMobile Playground app. Provides methods
 * for generating and parsing deep link URLs for navigation.
 */
object DeepLinkManager {

  private const val TAG = "DeepLinkManager"

  // Base deep link scheme and host
  private const val SCHEME = "automobile"
  private const val HOST = "playground"

  // Deep link paths for different destinations
  private const val PATH_ONBOARDING = "/onboarding"
  private const val PATH_LOGIN = "/login"
  private const val PATH_HOME = "/home"
  private const val PATH_MEDIA = "/media"
  private const val PATH_TAP = "/tap"
  private const val PATH_LONG_PRESS = "/long_press"
  private const val PATH_SWIPE = "/swipe"
  private const val PATH_TEXT = "/text"
  private const val PATH_CHAT = "/chat"
  private const val PATH_VIDEO = "/video"
  private const val PATH_SLIDES = "/slides"
  private const val PATH_VIDEO_PLAYER = "/video_player"
  private const val PATH_SETTINGS = "/settings"
  private const val PATH_DEMOS = "/demos"
  private const val PATH_DEMO_UX_START = "/demos/ux/start"
  private const val PATH_DEMO_UX_DETAILS = "/demos/ux/details"
  private const val PATH_DEMO_UX_SUMMARY = "/demos/ux/summary"
  private const val PATH_DEMO_STARTUP = "/demos/perf/startup"
  private const val PATH_DEMO_PERF_LIST = "/demos/perf/list"
  private const val PATH_DEMO_PERF_DETAIL = "/demos/perf/detail"
  private const val PATH_DEMO_A11Y_CONTRAST = "/demos/a11y/contrast"
  private const val PATH_DEMO_A11Y_TAP_TARGETS = "/demos/a11y/tap_targets"
  private const val PATH_DEMO_BUG_REPRO = "/demos/bugs/repro"

  /** Generate deep link URL for onboarding screen */
  fun generateOnboardingUrl(): String {
    val url = buildUri(PATH_ONBOARDING)
    Log.d(TAG, "Generated onboarding URL: $url")
    return url
  }

  /** Generate deep link URL for login screen */
  fun generateLoginUrl(): String {
    val url = buildUri(PATH_LOGIN)
    Log.d(TAG, "Generated login URL: $url")
    return url
  }

  /** Generate deep link URL for home screen */
  fun generateHomeUrl(): String {
    val url = buildUri(PATH_HOME)
    Log.d(TAG, "Generated home URL: $url")
    return url
  }

  /** Generate deep link URL for media/discover screen */
  fun generateMediaUrl(): String {
    val url = buildUri(PATH_MEDIA)
    Log.d(TAG, "Generated media URL: $url")
    return url
  }

  /** Generate deep link URL for tap screen (discover tab) */
  fun generateTapUrl(): String {
    val url = buildUri(PATH_TAP)
    Log.d(TAG, "Generated tap URL: $url")
    return url
  }

  /** Generate deep link URL for long press screen (discover tab alias) */
  fun generateLongPressUrl(): String {
    val url = buildUri(PATH_LONG_PRESS)
    Log.d(TAG, "Generated long press URL: $url")
    return url
  }

  /** Generate deep link URL for swipe screen (discover tab) */
  fun generateSwipeUrl(): String {
    val url = buildUri(PATH_SWIPE)
    Log.d(TAG, "Generated swipe URL: $url")
    return url
  }

  /** Generate deep link URL for text screen (discover tab) */
  fun generateTextUrl(): String {
    val url = buildUri(PATH_TEXT)
    Log.d(TAG, "Generated text URL: $url")
    return url
  }

  /** Generate deep link URL for chat screen (discover tab) */
  fun generateChatUrl(): String {
    val url = buildUri(PATH_CHAT)
    Log.d(TAG, "Generated chat URL: $url")
    return url
  }

  /** Generate deep link URL for video screen (discover tab) - alias for media */
  fun generateVideoUrl(): String {
    val url = buildUri(PATH_VIDEO)
    Log.d(TAG, "Generated video URL: $url")
    return url
  }

  /** Generate deep link URL for slides screen */
  fun generateSlidesUrl(slideIndex: Int = 0): String {
    val url = buildUri("$PATH_SLIDES/$slideIndex")
    Log.d(TAG, "Generated slides URL with slideIndex $slideIndex: $url")
    return url
  }

  /** Generate deep link URL for video player screen */
  fun generateVideoPlayerUrl(videoId: String): String {
    val url = buildUri("$PATH_VIDEO_PLAYER/$videoId")
    Log.d(TAG, "Generated video player URL with videoId '$videoId': $url")
    return url
  }

  /** Generate deep link URL for settings screen */
  fun generateSettingsUrl(): String {
    val url = buildUri(PATH_SETTINGS)
    Log.d(TAG, "Generated settings URL: $url")
    return url
  }

  /** Generate deep link URL for demo index screen */
  fun generateDemosIndexUrl(): String {
    val url = buildUri(PATH_DEMOS)
    Log.d(TAG, "Generated demos index URL: $url")
    return url
  }

  /** Generate deep link URL for demo UX flow start screen */
  fun generateDemoUxStartUrl(): String {
    val url = buildUri(PATH_DEMO_UX_START)
    Log.d(TAG, "Generated demo UX start URL: $url")
    return url
  }

  /** Generate deep link URL for demo UX flow details screen */
  fun generateDemoUxDetailsUrl(): String {
    val url = buildUri(PATH_DEMO_UX_DETAILS)
    Log.d(TAG, "Generated demo UX details URL: $url")
    return url
  }

  /** Generate deep link URL for demo UX flow summary screen */
  fun generateDemoUxSummaryUrl(): String {
    val url = buildUri(PATH_DEMO_UX_SUMMARY)
    Log.d(TAG, "Generated demo UX summary URL: $url")
    return url
  }

  /** Generate deep link URL for demo startup screen */
  fun generateDemoStartupUrl(): String {
    val url = buildUri(PATH_DEMO_STARTUP)
    Log.d(TAG, "Generated demo startup URL: $url")
    return url
  }

  /** Generate deep link URL for demo performance list screen */
  fun generateDemoPerformanceListUrl(): String {
    val url = buildUri(PATH_DEMO_PERF_LIST)
    Log.d(TAG, "Generated demo performance list URL: $url")
    return url
  }

  /** Generate deep link URL for demo performance detail screen */
  fun generateDemoPerformanceDetailUrl(itemId: Int): String {
    val url = buildUri("$PATH_DEMO_PERF_DETAIL/$itemId")
    Log.d(TAG, "Generated demo performance detail URL for itemId $itemId: $url")
    return url
  }

  /** Generate deep link URL for demo contrast screen */
  fun generateDemoContrastUrl(): String {
    val url = buildUri(PATH_DEMO_A11Y_CONTRAST)
    Log.d(TAG, "Generated demo contrast URL: $url")
    return url
  }

  /** Generate deep link URL for demo tap targets screen */
  fun generateDemoTapTargetsUrl(): String {
    val url = buildUri(PATH_DEMO_A11Y_TAP_TARGETS)
    Log.d(TAG, "Generated demo tap targets URL: $url")
    return url
  }

  /** Generate deep link URL for demo bug reproduction screen */
  fun generateDemoBugReproUrl(): String {
    val url = buildUri(PATH_DEMO_BUG_REPRO)
    Log.d(TAG, "Generated demo bug repro URL: $url")
    return url
  }

  /** Parse deep link URL and return the corresponding navigation destination */
  fun parseDeepLink(uri: Uri): AppDestination? {
    Log.d(TAG, "Parsing deep link URI: $uri")
    Log.d(
        TAG,
        "URI scheme: ${uri.scheme}, host: ${uri.host}, path: ${uri.path}, ssp: ${uri.schemeSpecificPart}",
    )

    if (uri.scheme != SCHEME) {
      Log.d(TAG, "Invalid scheme. Expected: $SCHEME")
      return null
    }

    // Determine if this is a hierarchical URI (automobile://playground/path) or opaque URI
    // (automobile:playground/path)
    val path =
        if (uri.host != null) {
          // Hierarchical URI: automobile://playground/path
          Log.d(TAG, "Parsing hierarchical URI format")
          if (uri.host != HOST) {
            Log.d(TAG, "Invalid host. Expected: $HOST, got: ${uri.host}")
            return null
          }
          // Extract path (already starts with "/")
          uri.path ?: ""
        } else {
          // Opaque URI: automobile:playground/path
          Log.d(TAG, "Parsing opaque URI format")
          val ssp = uri.schemeSpecificPart
          if (ssp == null || !ssp.startsWith(HOST)) {
            Log.d(TAG, "Invalid host. Expected scheme-specific part to start with: $HOST")
            return null
          }
          // Extract path from scheme-specific part (remove "playground" prefix)
          if (ssp.length > HOST.length) ssp.substring(HOST.length) else ""
        }

    if (path.isEmpty() && uri.schemeSpecificPart != HOST && uri.host != HOST) {
      Log.d(TAG, "Invalid URI format")
      return null
    }

    Log.d(TAG, "Extracted path: '$path'")

    val destination =
        when {
          path == PATH_ONBOARDING -> {
            Log.d(TAG, "Parsed as OnboardingDestination")
            OnboardingDestination
          }

          path == PATH_LOGIN -> {
            Log.d(TAG, "Parsed as LoginDestination")
            LoginDestination
          }

          path == PATH_HOME || path.isEmpty() -> {
            Log.d(TAG, "Parsed as HomeDestination with default tab (path: '$path')")
            HomeDestination(selectedTab = 0)
          }

          path == PATH_MEDIA -> {
            Log.d(TAG, "Parsed as HomeDestination with media/discover tab selected")
            HomeDestination(selectedTab = 0, selectedSubTab = 2) // Media sub-tab is index 2
          }

          path == PATH_TAP -> {
            Log.d(TAG, "Parsed as HomeDestination with tap sub-tab selected")
            HomeDestination(selectedTab = 0, selectedSubTab = 0) // Tap sub-tab is index 0
          }

          path == PATH_LONG_PRESS -> {
            Log.d(TAG, "Parsed as HomeDestination with tap sub-tab selected (long press alias)")
            HomeDestination(selectedTab = 0, selectedSubTab = 0) // Tap sub-tab is index 0
          }

          path == PATH_SWIPE -> {
            Log.d(TAG, "Parsed as HomeDestination with swipe sub-tab selected")
            HomeDestination(selectedTab = 0, selectedSubTab = 1) // Swipe sub-tab is index 1
          }

          path == PATH_TEXT -> {
            Log.d(TAG, "Parsed as HomeDestination with text sub-tab selected")
            HomeDestination(selectedTab = 0, selectedSubTab = 3) // Text sub-tab is index 3
          }

          path == PATH_CHAT -> {
            Log.d(TAG, "Parsed as HomeDestination with chat sub-tab selected")
            HomeDestination(selectedTab = 0, selectedSubTab = 4) // Chat sub-tab is index 4
          }

          path == PATH_VIDEO -> {
            Log.d(TAG, "Parsed as HomeDestination with video sub-tab selected (alias for media)")
            HomeDestination(selectedTab = 0, selectedSubTab = 2) // Video is same as Media sub-tab
          }

          path.startsWith(PATH_SLIDES) -> {
            val slideIndex = path.substringAfterLast("/").toIntOrNull()?.takeIf { it >= 0 } ?: 0
            Log.d(TAG, "Parsed as SlidesDestination with slideIndex: $slideIndex")
            SlidesDestination(slideIndex)
          }
          path.startsWith(PATH_VIDEO_PLAYER) -> {
            val videoId = path.substringAfterLast("/")
            if (videoId.isNotEmpty()) {
              Log.d(TAG, "Parsed as VideoPlayerDestination with videoId: '$videoId'")
              VideoPlayerDestination(videoId)
            } else {
              Log.d(TAG, "Empty videoId for video player path")
              null
            }
          }
          path == PATH_SETTINGS -> {
            Log.d(TAG, "Parsed as SettingsDestination")
            SettingsDestination
          }
          path == PATH_DEMOS -> {
            Log.d(TAG, "Parsed as DemoIndexDestination")
            DemoIndexDestination
          }
          path == PATH_DEMO_UX_START -> {
            Log.d(TAG, "Parsed as DemoUxStartDestination")
            DemoUxStartDestination
          }
          path == PATH_DEMO_UX_DETAILS -> {
            Log.d(TAG, "Parsed as DemoUxDetailsDestination")
            DemoUxDetailsDestination
          }
          path == PATH_DEMO_UX_SUMMARY -> {
            Log.d(TAG, "Parsed as DemoUxSummaryDestination")
            DemoUxSummaryDestination
          }
          path == PATH_DEMO_STARTUP -> {
            Log.d(TAG, "Parsed as DemoStartupDestination")
            DemoStartupDestination
          }
          path == PATH_DEMO_PERF_LIST -> {
            Log.d(TAG, "Parsed as DemoPerformanceListDestination")
            DemoPerformanceListDestination
          }
          path.startsWith(PATH_DEMO_PERF_DETAIL) -> {
            val itemId = path.substringAfterLast("/").toIntOrNull()
            if (itemId != null && itemId > 0) {
              Log.d(TAG, "Parsed as DemoPerformanceDetailDestination with itemId: $itemId")
              DemoPerformanceDetailDestination(itemId)
            } else {
              Log.d(TAG, "Invalid itemId for demo performance detail path")
              null
            }
          }
          path == PATH_DEMO_A11Y_CONTRAST -> {
            Log.d(TAG, "Parsed as DemoContrastDestination")
            DemoContrastDestination
          }
          path == PATH_DEMO_A11Y_TAP_TARGETS -> {
            Log.d(TAG, "Parsed as DemoTapTargetsDestination")
            DemoTapTargetsDestination
          }
          path == PATH_DEMO_BUG_REPRO -> {
            Log.d(TAG, "Parsed as DemoBugReproDestination")
            DemoBugReproDestination
          }
          else -> {
            Log.d(TAG, "No matching destination for path: $path")
            null
          }
        }

    Log.d(TAG, "Final parsed destination: $destination")
    return destination
  }

  /** Validate if a URI is a valid deep link for this app */
  fun isValidDeepLink(uri: Uri): Boolean {
    Log.d(TAG, "Validating deep link: $uri")

    // Check scheme first
    if (uri.scheme != SCHEME) {
      Log.d(TAG, "Deep link validation result: false (invalid scheme)")
      return false
    }

    // Handle both hierarchical (automobile://playground/path) and opaque
    // (automobile:playground/path) URIs
    val hasValidHost =
        if (uri.host != null) {
          // Hierarchical URI: check host
          uri.host == HOST
        } else {
          // Opaque URI: check scheme-specific part
          uri.schemeSpecificPart?.startsWith(HOST) == true
        }

    if (!hasValidHost) {
      Log.d(TAG, "Deep link validation result: false (invalid host)")
      return false
    }

    // Try to parse the deep link
    val isValid = parseDeepLink(uri) != null
    Log.d(TAG, "Deep link validation result: $isValid")
    return isValid
  }

  /** Get the destination name from a deep link URI */
  fun getDestinationName(uri: Uri): String? {
    Log.d(TAG, "Getting destination name for URI: $uri")

    if (!isValidDeepLink(uri)) {
      Log.d(TAG, "Invalid deep link, returning null destination name")
      return null
    }

    // Extract path from scheme-specific part for opaque URIs
    val ssp = uri.schemeSpecificPart
    if (ssp == null || !ssp.startsWith(HOST)) {
      Log.d(TAG, "Invalid URI format, returning null destination name")
      return null
    }

    val path = if (ssp.length > HOST.length) ssp.substring(HOST.length) else ""

    val destinationName =
        when {
          path == PATH_ONBOARDING -> "Onboarding"
          path == PATH_LOGIN -> "Login"
          path == PATH_HOME || path.isEmpty() -> "Home"
          path == PATH_MEDIA -> "Media"
          path == PATH_TAP -> "Tap"
          path == PATH_LONG_PRESS -> "Tap"
          path == PATH_SWIPE -> "Swipe"
          path == PATH_TEXT -> "Text"
          path == PATH_CHAT -> "Chat"
          path == PATH_VIDEO -> "Video"
          path.startsWith(PATH_SLIDES) -> "Slides"
          path.startsWith(PATH_VIDEO_PLAYER) -> "Video Player"
          path == PATH_SETTINGS -> "Settings"
          path == PATH_DEMOS -> "Demo Index"
          path == PATH_DEMO_UX_START -> "Demo UX Start"
          path == PATH_DEMO_UX_DETAILS -> "Demo UX Details"
          path == PATH_DEMO_UX_SUMMARY -> "Demo UX Summary"
          path == PATH_DEMO_STARTUP -> "Demo Startup"
          path == PATH_DEMO_PERF_LIST -> "Demo Performance List"
          path.startsWith(PATH_DEMO_PERF_DETAIL) -> "Demo Performance Detail"
          path == PATH_DEMO_A11Y_CONTRAST -> "Demo Contrast"
          path == PATH_DEMO_A11Y_TAP_TARGETS -> "Demo Tap Targets"
          path == PATH_DEMO_BUG_REPRO -> "Demo Bug Repro"
          else -> null
        }

    Log.d(TAG, "Destination name: $destinationName")
    return destinationName
  }

  // AutoMobile test integration methods

  /** Navigate to onboarding screen via deep link for AutoMobile tests */
  fun navigateToOnboardingForTest(context: Context) {
    Log.d(TAG, "Navigating to onboarding for test")
    launchDeepLink(context, generateOnboardingUrl())
  }

  /** Navigate to login screen via deep link for AutoMobile tests */
  fun navigateToLoginForTest(context: Context) {
    Log.d(TAG, "Navigating to login for test")
    launchDeepLink(context, generateLoginUrl())
  }

  /** Navigate to home screen via deep link for AutoMobile tests */
  fun navigateToHomeForTest(context: Context) {
    Log.d(TAG, "Navigating to home for test")
    launchDeepLink(context, generateHomeUrl())
  }

  /** Navigate to media/discover screen via deep link for AutoMobile tests */
  fun navigateToMediaForTest(context: Context) {
    Log.d(TAG, "Navigating to media for test")
    launchDeepLink(context, generateMediaUrl())
  }

  /** Navigate to tap screen (discover tab) via deep link for AutoMobile tests */
  fun navigateToTapForTest(context: Context) {
    Log.d(TAG, "Navigating to tap for test")
    launchDeepLink(context, generateTapUrl())
  }

  /** Navigate to long press screen (discover tab alias) via deep link for AutoMobile tests */
  fun navigateToLongPressForTest(context: Context) {
    Log.d(TAG, "Navigating to long press for test")
    launchDeepLink(context, generateLongPressUrl())
  }

  /** Navigate to swipe screen (discover tab) via deep link for AutoMobile tests */
  fun navigateToSwipeForTest(context: Context) {
    Log.d(TAG, "Navigating to swipe for test")
    launchDeepLink(context, generateSwipeUrl())
  }

  /** Navigate to text screen (discover tab) via deep link for AutoMobile tests */
  fun navigateToTextForTest(context: Context) {
    Log.d(TAG, "Navigating to text for test")
    launchDeepLink(context, generateTextUrl())
  }

  /** Navigate to chat screen (discover tab) via deep link for AutoMobile tests */
  fun navigateToChatForTest(context: Context) {
    Log.d(TAG, "Navigating to chat for test")
    launchDeepLink(context, generateChatUrl())
  }

  /** Navigate to video screen (discover tab) via deep link for AutoMobile tests */
  fun navigateToVideoForTest(context: Context) {
    Log.d(TAG, "Navigating to video for test")
    launchDeepLink(context, generateVideoUrl())
  }

  /** Navigate to slides screen via deep link for AutoMobile tests */
  fun navigateToSlidesForTest(context: Context, slideIndex: Int = 0) {
    Log.d(TAG, "Navigating to slides for test with slideIndex: $slideIndex")
    launchDeepLink(context, generateSlidesUrl(slideIndex))
  }

  /** Navigate to video player screen via deep link for AutoMobile tests */
  fun navigateToVideoPlayerForTest(context: Context, videoId: String) {
    Log.d(TAG, "Navigating to video player for test with videoId: '$videoId'")
    launchDeepLink(context, generateVideoPlayerUrl(videoId))
  }

  /** Navigate to settings screen via deep link for AutoMobile tests */
  fun navigateToSettingsForTest(context: Context) {
    Log.d(TAG, "Navigating to settings for test")
    launchDeepLink(context, generateSettingsUrl())
  }

  /** Navigate to demos index screen via deep link for AutoMobile tests */
  fun navigateToDemosIndexForTest(context: Context) {
    Log.d(TAG, "Navigating to demos index for test")
    launchDeepLink(context, generateDemosIndexUrl())
  }

  /** Navigate to demo UX flow start via deep link for AutoMobile tests */
  fun navigateToDemoUxStartForTest(context: Context) {
    Log.d(TAG, "Navigating to demo UX start for test")
    launchDeepLink(context, generateDemoUxStartUrl())
  }

  /** Navigate to demo UX flow details via deep link for AutoMobile tests */
  fun navigateToDemoUxDetailsForTest(context: Context) {
    Log.d(TAG, "Navigating to demo UX details for test")
    launchDeepLink(context, generateDemoUxDetailsUrl())
  }

  /** Navigate to demo UX flow summary via deep link for AutoMobile tests */
  fun navigateToDemoUxSummaryForTest(context: Context) {
    Log.d(TAG, "Navigating to demo UX summary for test")
    launchDeepLink(context, generateDemoUxSummaryUrl())
  }

  /** Navigate to demo startup screen via deep link for AutoMobile tests */
  fun navigateToDemoStartupForTest(context: Context) {
    Log.d(TAG, "Navigating to demo startup for test")
    launchDeepLink(context, generateDemoStartupUrl())
  }

  /** Navigate to demo performance list screen via deep link for AutoMobile tests */
  fun navigateToDemoPerformanceListForTest(context: Context) {
    Log.d(TAG, "Navigating to demo performance list for test")
    launchDeepLink(context, generateDemoPerformanceListUrl())
  }

  /** Navigate to demo performance detail screen via deep link for AutoMobile tests */
  fun navigateToDemoPerformanceDetailForTest(context: Context, itemId: Int) {
    Log.d(TAG, "Navigating to demo performance detail for test with itemId: $itemId")
    launchDeepLink(context, generateDemoPerformanceDetailUrl(itemId))
  }

  /** Navigate to demo contrast screen via deep link for AutoMobile tests */
  fun navigateToDemoContrastForTest(context: Context) {
    Log.d(TAG, "Navigating to demo contrast for test")
    launchDeepLink(context, generateDemoContrastUrl())
  }

  /** Navigate to demo tap targets screen via deep link for AutoMobile tests */
  fun navigateToDemoTapTargetsForTest(context: Context) {
    Log.d(TAG, "Navigating to demo tap targets for test")
    launchDeepLink(context, generateDemoTapTargetsUrl())
  }

  /** Navigate to demo bug reproduction screen via deep link for AutoMobile tests */
  fun navigateToDemoBugReproForTest(context: Context) {
    Log.d(TAG, "Navigating to demo bug repro for test")
    launchDeepLink(context, generateDemoBugReproUrl())
  }

  /** Generic method to launch a deep link intent for testing */
  fun launchDeepLink(context: Context, deepLinkUrl: String) {
    Log.d(TAG, "Launching deep link: $deepLinkUrl")
    Log.d(TAG, "Context package name: ${context.packageName}")

    val intent =
        Intent(Intent.ACTION_VIEW, Uri.parse(deepLinkUrl)).apply {
          setPackage(context.packageName)
          flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
        }

    Log.d(TAG, "Intent created with flags: ${intent.flags}")
    Log.d(TAG, "Starting activity with intent")

    try {
      context.startActivity(intent)
      Log.d(TAG, "Successfully started activity for deep link")
    } catch (e: Exception) {
      Log.e(TAG, "Failed to start activity for deep link", e)
    }
  }

  /** Get all available deep link URLs for testing purposes */
  fun getAllDeepLinks(): List<Pair<String, String>> {
    Log.d(TAG, "Getting all available deep links")
    val deepLinks =
        listOf(
            "Onboarding" to generateOnboardingUrl(),
            "Login" to generateLoginUrl(),
            "Home" to generateHomeUrl(),
            "Media" to generateMediaUrl(),
            "Tap" to generateTapUrl(),
            "Long Press (alias)" to generateLongPressUrl(),
            "Swipe" to generateSwipeUrl(),
            "Text" to generateTextUrl(),
            "Chat" to generateChatUrl(),
            "Video" to generateVideoUrl(),
            "Slides (slide 0)" to generateSlidesUrl(0),
            "Slides (slide 3)" to generateSlidesUrl(3),
            "Video Player (sample)" to generateVideoPlayerUrl("sample123"),
            "Settings" to generateSettingsUrl(),
            "Demos Index" to generateDemosIndexUrl(),
            "Demo UX Start" to generateDemoUxStartUrl(),
            "Demo UX Details" to generateDemoUxDetailsUrl(),
            "Demo UX Summary" to generateDemoUxSummaryUrl(),
            "Demo Startup" to generateDemoStartupUrl(),
            "Demo Performance List" to generateDemoPerformanceListUrl(),
            "Demo Performance Detail (item 4)" to generateDemoPerformanceDetailUrl(4),
            "Demo Contrast" to generateDemoContrastUrl(),
            "Demo Tap Targets" to generateDemoTapTargetsUrl(),
            "Demo Bug Repro" to generateDemoBugReproUrl(),
        )
    Log.d(TAG, "Generated ${deepLinks.size} deep links")
    return deepLinks
  }

  private fun buildUri(path: String): String {
    // Build opaque URI in format "automobile:playground/path" instead of
    // "automobile://playground/path"
    val uri = "$SCHEME:$HOST$path"
    Log.d(TAG, "Built URI with path '$path': $uri")
    return uri
  }
}
