# vulnx bash completion script
_vulnx_completion() {
    local cur prev commands
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Available commands
    commands="analyze auth completion filters healthcheck id mcp search update version help"

    # Available shells for completion command
    shells="bash zsh fish powershell"

    # Global flags (available for all commands)
    global_flags="--help --debug --verbose --json --output --silent --no-color --proxy --timeout --debug-req --debug-resp"

    case "${prev}" in
        vulnx)
            COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
            return 0
            ;;
        completion)
            COMPREPLY=( $(compgen -W "${shells}" -- ${cur}) )
            return 0
            ;;
        analyze)
            COMPREPLY=( $(compgen -W "--fields -f --query -q --facet-size ${global_flags}" -- ${cur}) )
            return 0
            ;;
        search)
            COMPREPLY=( $(compgen -W "--limit -n --offset --sort-asc --sort-desc --fields --term-facets --range-facets --highlight --facet-size --detailed --product -p --vendor --severity -s --vuln-status --vuln-age -a --kev --template -t --poc --hackerone --remote-exploit --cvss-score --epss-score --tags --vuln-type ${global_flags}" -- ${cur}) )
            return 0
            ;;
        id)
            COMPREPLY=( $(compgen -W "--file ${global_flags}" -- ${cur}) )
            return 0
            ;;
        auth)
            COMPREPLY=( $(compgen -W "--api-key --test ${global_flags}" -- ${cur}) )
            return 0
            ;;
        healthcheck|health|hc)
            COMPREPLY=( $(compgen -W "${global_flags}" -- ${cur}) )
            return 0
            ;;
        mcp)
            COMPREPLY=( $(compgen -W "--mode --port ${global_flags}" -- ${cur}) )
            return 0
            ;;
        update)
            COMPREPLY=( $(compgen -W "--disable-update-check ${global_flags}" -- ${cur}) )
            return 0
            ;;
        filters)
            COMPREPLY=( $(compgen -W "${global_flags}" -- ${cur}) )
            return 0
            ;;
        version)
            COMPREPLY=( $(compgen -W "--disable-update-check ${global_flags}" -- ${cur}) )
            return 0
            ;;
        --*)
            # Don't complete after flags
            return 0
            ;;
        *)
            # Default to global flags
            COMPREPLY=( $(compgen -W "${global_flags}" -- ${cur}) )
            return 0
            ;;
    esac
}

complete -F _vulnx_completion vulnx
