# Test Command Module
# Main entry point for test environment commands

export use ../test_environments.nu *

# Main test command dispatcher
export def main [
    subcommand?: string
    ...args
] {
    match $subcommand {
        "env" => {
            # Delegate to test_environments.nu
            ^$"((get-provisioning-name))" test env ...$args
        }
        "topology" => {
            ^$"((get-provisioning-name))" test topology ...$args
        }
        "quick" => {
            ^$"((get-provisioning-name))" test quick ...$args
        }
        "help" | "-h" | "--help" => {
            print_test_help
        }
        _ => {
            if ($subcommand | is-empty) {
                print_test_help
            } else {
                _print $"Unknown test subcommand: ($subcommand)"
                _print "Run 'provisioning test help' for available commands"
            }
        }
    }
}

def print_test_help [] {
    _print $"
(_ansi cyan_bold)Test Environment Management(_ansi reset)

(_ansi green_bold)Environment Commands:(_ansi reset)
  test env create <config>     Create test environment from config
  test env single <taskserv>   Create single taskserv test
  test env server <name>       Create server simulation test
  test env cluster <type>      Create cluster topology test
  test env list                List all test environments
  test env get <id>            Get environment details
  test env run <id>            Run tests in environment
  test env logs <id>           Get environment logs
  test env status <id>         Show environment status
  test env cleanup <id>        Cleanup environment

(_ansi green_bold)Topology Commands:(_ansi reset)
  test topology list           List available topology templates
  test topology load <name>    Load topology template

(_ansi green_bold)Quick Test:(_ansi reset)
  test quick <taskserv>        Quick test (create, run, cleanup)

(_ansi green_bold)Examples:(_ansi reset)
  # Single taskserv test
  provisioning test env single kubernetes --auto-start --auto-cleanup

  # Server simulation with multiple taskservs
  provisioning test env server web-01 [containerd kubernetes cilium] --auto-start

  # Cluster from template
  provisioning test topology load kubernetes_3node | test env cluster kubernetes

  # Quick test
  provisioning test quick redis

(_ansi green_bold)Flags:(_ansi reset)
  --infra <name>      Infrastructure context
  --auto-start        Auto-start tests after creation
  --auto-cleanup      Auto-cleanup after completion
  --cpu <cores>       CPU millicores (default: 1000)
  --memory <mb>       Memory MB (default: 2048)

(_ansi default_dimmed)💡 Test environments run in isolated Docker containers
   Ensure Docker daemon is running before using test commands(_ansi reset)
"
}
