#!/usr/bin/env nu

# Guide generators for documentation
#
# Generates user-facing guides:
# - Getting started guide
# - Installation guide
# - CLI reference
# - Troubleshooting guide
# - FAQ

use std log

# Generate user documentation guides
export def generate_user_documentation [docs_config: record, discovery_result: record] {
    log info "Generating user documentation..."

    let start_time = (date now)

    let result = (do {
        let user_docs_dir = ($docs_config.output_dir | path join "user")
        mkdir $user_docs_dir

        mut generated_docs = []

        # Generate getting started guide
        let getting_started = generate_getting_started_guide $docs_config $discovery_result

        $getting_started | save ($user_docs_dir | path join "getting-started.md")
        $generated_docs = ($generated_docs | append "getting-started.md")

        # Generate installation guide
        let installation_guide = generate_installation_guide $docs_config $discovery_result

        $installation_guide | save ($user_docs_dir | path join "installation.md")
        $generated_docs = ($generated_docs | append "installation.md")

        # Generate CLI reference
        let cli_reference = generate_cli_reference $docs_config $discovery_result

        $cli_reference | save ($user_docs_dir | path join "cli-reference.md")
        $generated_docs = ($generated_docs | append "cli-reference.md")

        # Generate troubleshooting guide
        let troubleshooting = generate_troubleshooting_guide $docs_config $discovery_result

        $troubleshooting | save ($user_docs_dir | path join "troubleshooting.md")
        $generated_docs = ($generated_docs | append "troubleshooting.md")

        # Generate FAQ
        let faq = generate_faq $docs_config $discovery_result

        $faq | save ($user_docs_dir | path join "faq.md")
        $generated_docs = ($generated_docs | append "faq.md")

        {
            status: "success"
            docs_generated: ($generated_docs | length)
            generated_docs: $generated_docs
            user_docs_dir: $user_docs_dir
            duration: ((date now) - $start_time)
        }
    } | complete)

    if $result.exit_code != 0 {
        {
            status: "failed"
            reason: $result.stderr
            duration: ((date now) - $start_time)
        }
    } else {
        $result.stdout
    }
}

# Generate getting started guide (placeholder - content generated at runtime)
def generate_getting_started_guide [docs_config: record, discovery_result: record] {
    "# Getting Started with Provisioning System\n\nThis is a placeholder guide generated at runtime."
}

# Generate installation guide (placeholder - content generated at runtime)
def generate_installation_guide [docs_config: record, discovery_result: record] {
    "# Installation Guide\n\nThis is a placeholder installation guide generated at runtime."
}

# Generate CLI reference (placeholder - content generated at runtime)
def generate_cli_reference [docs_config: record, discovery_result: record] {
    "# CLI Reference\n\nThis is a placeholder CLI reference generated at runtime."
}

# Generate troubleshooting guide (placeholder - content generated at runtime)
def generate_troubleshooting_guide [docs_config: record, discovery_result: record] {
    "# Troubleshooting Guide\n\nThis is a placeholder troubleshooting guide generated at runtime."
}

# Generate FAQ (placeholder - content generated at runtime)
def generate_faq [docs_config: record, discovery_result: record] {
    "# Frequently Asked Questions\n\nThis is a placeholder FAQ generated at runtime."
}
