## Test container manager functionality

import std/[os, strutils, options]
import ../src/nimpak/build/container_manager

proc testContainerDetection() =
  echo "Testing container runtime detection..."

  let runtimeOpt = detectContainerRuntime()

  if runtimeOpt.isSome:
    let runtime = runtimeOpt.get()
    echo "✓ Detected: ", runtime.runtime
    echo "  Version: ", runtime.version
    echo "  Path: ", runtime.path
    echo "  Rootless: ", runtime.rootless
  else:
    echo "✗ No container runtime detected"
    echo "  This is expected if Podman/Docker/nerdctl is not installed"

proc testAllRuntimes() =
  echo "\nTesting all runtime detection..."

  let runtimes = getAllRuntimes()

  if runtimes.len == 0:
    echo "✗ No runtimes found"
  else:
    echo "✓ Found ", runtimes.len, " runtime(s):"
    for runtime in runtimes:
      echo "  - ", runtime.runtime, " (", runtime.version, ")"

proc testContainerManager() =
  echo "\nTesting ContainerManager..."

  let cm = newContainerManager()

  if cm.isAvailable():
    echo "✓ Container manager available"
    echo "  Runtime: ", cm.runtime
    echo "  Command: ", cm.getRuntimeCommand()
    echo "  Rootless: ", cm.rootless
  else:
    echo "✗ Container manager not available"
    echo "  Install Podman: sudo pacman -S podman"

proc testImageOperations() =
  echo "\nTesting image operations..."

  let cm = newContainerManager()

  if not cm.isAvailable():
    echo "✗ Skipping (no runtime available)"
    return

  # List images
  echo "Listing images..."
  let images = cm.listImages()
  echo "✓ Found ", images.len, " images"

  if images.len > 0:
    echo "  First few images:"
    for i, image in images:
      if i >= 3: break
      echo "    - ", image

proc main() =
  echo "Container Manager Tests"
  echo "======================="
  echo ""

  testContainerDetection()
  testAllRuntimes()
  testContainerManager()
  testImageOperations()

  echo ""
  echo "Tests complete!"

when isMainModule:
  main()
