# apt-ostree bash completion
# Generated for apt-ostree version 0.1.0

_apt_ostree()
{
    local cur prev opts cmds
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Main commands
    cmds="info search install remove upgrade rollback status help version"

    # Global options
    opts="--help --version --verbose --quiet --config --data-dir --log-level"

    # If this is the first word, complete with commands
    if [[ ${COMP_CWORD} -eq 1 ]]; then
        COMPREPLY=( $(compgen -W "${cmds}" -- "${cur}") )
        return 0
    fi

    # Handle command-specific completions
    case "${prev}" in
        info)
            # Complete with package names from APT cache
            if command -v apt-cache >/dev/null 2>&1; then
                local packages=$(apt-cache --no-generate pkgnames 2>/dev/null | grep -i "^${cur}" | head -20)
                COMPREPLY=( $(compgen -W "${packages}" -- "${cur}") )
            fi
            ;;
        search)
            # Complete with common search terms
            local search_terms="package name description maintainer"
            COMPREPLY=( $(compgen -W "${search_terms}" -- "${cur}") )
            ;;
        install|remove)
            # Complete with package names from APT cache
            if command -v apt-cache >/dev/null 2>&1; then
                local packages=$(apt-cache --no-generate pkgnames 2>/dev/null | grep -i "^${cur}" | head -20)
                COMPREPLY=( $(compgen -W "${packages}" -- "${cur}") )
            fi
            ;;
        --config)
            # Complete with configuration files
            COMPREPLY=( $(compgen -f -X "!*.toml" -- "${cur}") )
            ;;
        --data-dir)
            # Complete with directories
            COMPREPLY=( $(compgen -d -- "${cur}") )
            ;;
        --log-level)
            # Complete with log levels
            local log_levels="trace debug info warn error"
            COMPREPLY=( $(compgen -W "${log_levels}" -- "${cur}") )
            ;;
        *)
            # Complete with global options if not a command
            if [[ ${cur} == -* ]]; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            fi
            ;;
    esac

    return 0
}

# Register the completion function
complete -F _apt_ostree apt-ostree

# Also complete for the short alias if it exists
complete -F _apt_ostree aost 2>/dev/null || true
