#!/usr/bin/env nu
# Router for New Setup System
# This file routes setup commands to the main provisioning CLI
# Author: JesusPerezLorenzo
# Release: 1.0.5
# Date: 2025-12-09

# Main entry point - delegate to main provisioning CLI
def main [
  ...args: string                  # Command arguments
  --debug (-x)                      # Debug mode
  --check (-c)                      # Dry-run mode
  --yes (-y)                        # Auto-confirm
  --verbose (-v)                    # Verbose output
  --interactive                     # Interactive mode
  --notitles                        # Suppress titles
  --out: string = ""                # Output format
  --helpinfo (-h)                   # Show help
]: nothing -> nothing {
  # Build command-line arguments to pass to main provisioning CLI
  let cli_args = [
    "setup",
    ...(if ($args | length) > 0 { $args } else { [] }),
    ...(if $check { ["--check"] } else { [] }),
    ...(if $verbose { ["--verbose"] } else { [] }),
    ...(if $yes { ["--yes"] } else { [] }),
    ...(if $interactive { ["--interactive"] } else { [] }),
    ...(if $debug { ["--debug"] } else { [] }),
    ...(if ($out | is-not-empty) { [$"--out=$out"] } else { [] }),
    ...(if $helpinfo { ["--help"] } else { [] })
  ]

  # Determine provisioning command location
  let provisioning_cmd = (
    if ($env.PROVISIONING? | is-not-empty) {
      $"($env.PROVISIONING)/core/cli/provisioning"
    } else if ($env.PROVISIONING_NAME? | is-not-empty) {
      $env.PROVISIONING_NAME
    } else {
      "provisioning"
    }
  )

  # Delegate to main provisioning CLI
  ^$provisioning_cmd ...$cli_args
}

# Display help for setup
def show-setup-help [] {
  print ""
  print "╔═══════════════════════════════════════════════════════════════╗"
  print "║              PROVISIONING SETUP SYSTEM                       ║"
  print "║                                                               ║"
  print "║  Complete system initialization and configuration management ║"
  print "╚═══════════════════════════════════════════════════════════════╝"
  print ""

  print "USAGE:"
  print "  provisioning setup <command> [OPTIONS]"
  print ""

  print "COMMANDS:"
  print "  system              Complete system setup (interactive, defaults, minimal)"
  print "  workspace           Create and configure workspaces"
  print "  provider            Setup infrastructure providers (UpCloud, AWS, Hetzner)"
  print "  platform            Configure platform services (Orchestrator, Control-Center, KMS)"
  print "  update              Update existing configuration"
  print "  wizard              Interactive setup wizard"
  print "  validate            Validate current configuration"
  print "  detect              Detect system capabilities"
  print "  migrate             Migrate existing configurations"
  print "  status              Show setup status"
  print "  help                Show this help message"
  print ""

  print "COMMON EXAMPLES:"
  print "  # Interactive setup (recommended)"
  print "  provisioning setup system --interactive"
  print ""
  print "  # Setup with defaults"
  print "  provisioning setup system --defaults"
  print ""
  print "  # Check system capabilities"
  print "  provisioning setup detect --verbose"
  print ""
  print "  # Validate configuration"
  print "  provisioning setup validate"
  print ""
  print "  # Migrate existing workspace"
  print "  provisioning setup migrate --auto"
  print ""

  print "OPTIONS:"
  print "  --check, -c         Dry-run without making changes"
  print "  --verbose, -v       Show detailed output"
  print "  --yes, -y           Auto-confirm prompts"
  print "  --interactive       Use interactive mode"
  print ""

  print "CONFIGURATION LOCATIONS:"
  print "  macOS:              ~/Library/Application Support/provisioning/"
  print "  Linux:              ~/.config/provisioning/"
  print "  Windows:            %APPDATA%/provisioning/"
  print ""

  print "For help on specific commands:"
  print "  provisioning setup <command> --help"
  print ""
}
