# Help System String Extractor
# Extracts user-visible strings from help system for i18n
# Processes help_system.nu and generates Fluent catalogs

# Extract main help menu strings
export def extract-help-main [] {
    [
        {key: "help-main-title", en: "PROVISIONING SYSTEM"}
        {key: "help-main-subtitle", en: "Layered Infrastructure Automation"}
        {key: "help-main-categories", en: "COMMAND CATEGORIES"}
        {key: "help-main-categories-hint", en: "Use 'provisioning help <category>' for details"}

        {key: "help-main-infrastructure-name", en: "infrastructure"}
        {key: "help-main-infrastructure-desc", en: "Server, taskserv, cluster, VM, and infra management"}
        {key: "help-main-orchestration-name", en: "orchestration"}
        {key: "help-main-orchestration-desc", en: "Workflow, batch operations, and orchestrator control"}
        {key: "help-main-development-name", en: "development"}
        {key: "help-main-development-desc", en: "Module discovery, layers, versions, and packaging"}
        {key: "help-main-workspace-name", en: "workspace"}
        {key: "help-main-workspace-desc", en: "Workspace and template management"}
        {key: "help-main-platform-name", en: "platform"}
        {key: "help-main-platform-desc", en: "Orchestrator, Control Center, MCP, and services"}
        {key: "help-main-setup-name", en: "setup"}
        {key: "help-main-setup-desc", en: "System setup, configuration, and initialization"}
        {key: "help-main-authentication-name", en: "authentication"}
        {key: "help-main-authentication-desc", en: "JWT authentication, MFA, and sessions"}
        {key: "help-main-plugins-name", en: "plugins"}
        {key: "help-main-plugins-desc", en: "Plugin management and plugin operations"}
        {key: "help-main-utilities-name", en: "utilities"}
        {key: "help-main-utilities-desc", en: "Cache, SOPS, providers, SSH, and tools"}
        {key: "help-main-tools-name", en: "tools"}
        {key: "help-main-tools-desc", en: "Tool and dependency management"}
        {key: "help-main-vm-name", en: "vm"}
        {key: "help-main-vm-desc", en: "Virtual machine operations and lifecycle"}
        {key: "help-main-diagnostics-name", en: "diagnostics"}
        {key: "help-main-diagnostics-desc", en: "System status, health checks, and debugging"}
        {key: "help-main-concepts-name", en: "concepts"}
        {key: "help-main-concepts-desc", en: "Architecture and key concepts"}
        {key: "help-main-guides-name", en: "guides"}
        {key: "help-main-guides-desc", en: "Quick guides and cheatsheets"}
        {key: "help-main-integrations-name", en: "integrations"}
        {key: "help-main-integrations-desc", en: "Prov-ecosystem and provctl bridge"}

        {key: "help-error-unknown-category", en: "Unknown help category"}
        {key: "help-error-available-categories", en: "Available help categories"}
        {key: "help-error-use-help", en: "Use 'provisioning help' for main help"}
    ]
}

# Extract infrastructure help strings
export def extract-help-infrastructure [] {
    [
        {key: "help-infrastructure-title", en: "SERVER & INFRASTRUCTURE"}

        {key: "help-infra-server", en: "Server Operations"}
        {key: "help-infra-server-create", en: "Create a new server"}
        {key: "help-infra-server-list", en: "List all servers"}
        {key: "help-infra-server-status", en: "Show server status"}
        {key: "help-infra-server-delete", en: "Delete server"}

        {key: "help-infra-taskserv", en: "TaskServ Management"}
        {key: "help-infra-taskserv-create", en: "Deploy taskserv to server"}
        {key: "help-infra-taskserv-list", en: "List taskservs"}
        {key: "help-infra-taskserv-logs", en: "View taskserv logs"}
        {key: "help-infra-taskserv-delete", en: "Remove taskserv"}

        {key: "help-infra-cluster", en: "Cluster Management"}
        {key: "help-infra-cluster-create", en: "Create cluster"}
        {key: "help-infra-cluster-add-node", en: "Add cluster node"}
        {key: "help-infra-cluster-remove-node", en: "Remove cluster node"}
        {key: "help-infra-cluster-status", en: "Get cluster status"}

        {key: "help-infra-vm", en: "Virtual Machine Operations"}
        {key: "help-infra-vm-create", en: "Create virtual machine"}
        {key: "help-infra-vm-start", en: "Start VM"}
        {key: "help-infra-vm-stop", en: "Stop VM"}
        {key: "help-infra-vm-reboot", en: "Reboot VM"}

        {key: "help-infra-tip", en: "Use filters and selectors to target multiple resources"}
    ]
}

# Extract orchestration help strings
export def extract-help-orchestration [] {
    [
        {key: "help-orchestration-title", en: "ORCHESTRATION & WORKFLOWS"}
        {key: "help-orch-control", en: "Orchestrator Management"}
        {key: "help-orch-start", en: "Start orchestrator [--background]"}
        {key: "help-orch-stop", en: "Stop orchestrator"}
        {key: "help-orch-status", en: "Check if running"}
        {key: "help-orch-health", en: "Health check"}
        {key: "help-orch-logs", en: "View logs [--follow]"}

        {key: "help-orch-workflows", en: "Single Task Workflows"}
        {key: "help-orch-workflow-list", en: "List all workflows"}
        {key: "help-orch-workflow-status", en: "Get workflow status"}
        {key: "help-orch-workflow-monitor", en: "Monitor in real-time"}
        {key: "help-orch-workflow-stats", en: "Show statistics"}
        {key: "help-orch-workflow-cleanup", en: "Clean old workflows"}

        {key: "help-orch-batch", en: "Multi-Provider Batch Operations"}
        {key: "help-orch-batch-submit", en: "Submit Nickel workflow [--wait]"}
        {key: "help-orch-batch-list", en: "List batches [--status Running]"}
        {key: "help-orch-batch-status", en: "Get batch status"}
        {key: "help-orch-batch-monitor", en: "Real-time monitoring"}
        {key: "help-orch-batch-rollback", en: "Rollback failed batch"}
        {key: "help-orch-batch-cancel", en: "Cancel running batch"}
        {key: "help-orch-batch-stats", en: "Show statistics"}

        {key: "help-orch-tip", en: "Batch workflows support mixed providers: UpCloud, AWS, and local"}
        {key: "help-orch-example", en: "provisioning batch submit deployment.ncl --wait"}
    ]
}

# Generate Fluent format from string catalog
export def generate-fluent-help [
    strings: list
    --language: string = "en-US"
] {
    let header = $"# Help System Translations\n# Language: ($language)\n# Category: Help text and menu items\n# Generated by help_string_extractor.nu\n\n"

    let fluent_entries = (
        $strings
        | reduce -f [] { |item, acc|
            let value = (if $language == "en-US" { $item.en } else { "[NEEDS TRANSLATION]" })
            let line = ($item.key + " = " + $value)
            $acc | append $line
        }
        | str join "\n"
    )

    $header + $fluent_entries + "\n"
}

# Combine all help strings
export def extract-all-help [] {
    let main = (extract-help-main)
    let infra = (extract-help-infrastructure)
    let orch = (extract-help-orchestration)

    ($main | append $infra | append $orch)
}
