#compdef qpdf
# qpdf zsh completion
#
# Most of this logic was generated by Anthropic Claude Opus 4.7. The
# tabular data is automatically generated.
#
# Two usage modes:
#   1. Source it at runtime (e.g. `source <(qpdf --completion-zsh)` in
#      .zshrc, after `autoload -U compinit && compinit`). The compdef
#      call at the bottom of this file registers the binding.
#   2. Install this file as `_qpdf` in a directory on $fpath. The
#      `#compdef qpdf` header above tells compinit to autoload it on
#      demand; the explicit compdef call at the bottom is a harmless
#      no-op in that mode.

_qpdf() {
    emulate -L zsh
    setopt local_options extended_glob no_sh_word_split
    typeset -A opts arity values nexttab vnext

    _def() {
        arity[$1.$2]=$3
        values[$1.$2]=$4
        nexttab[$1.$2]=$5
    }

    # BEGIN GENERATED
    opts[help]="--version --copyright --show-crypto --job-json-help --zopfli --json-help --completion-bash --completion-zsh --help"
    opts[global]="--no-default-limits --parser-max-container-size --parser-max-container-size-damaged --parser-max-errors --parser-max-nesting --max-stream-filters"
    opts[main]="--add-attachment --allow-weak-crypto --check --check-linearization --coalesce-contents --copy-attachments-from --decrypt --deterministic-id --empty --encrypt --externalize-inline-images --filtered-stream-data --flatten-rotation --generate-appearances --global --ignore-xref-streams --is-encrypted --json-input --keep-inline-images --linearize --list-attachments --newline-before-endstream --no-original-object-ids --no-warn --optimize-images --overlay --pages --password-is-hex-key --preserve-unreferenced --preserve-unreferenced-resources --progress --qdf --raw-stream-data --recompress-flate --remove-acroform --remove-info --remove-metadata --remove-page-labels --remove-structure --replace-input --report-memory-usage --requires-password --remove-restrictions --set-page-labels --show-encryption --show-encryption-key --show-linearization --show-npages --show-pages --show-xref --static-aes-iv --static-id --suppress-password-recovery --suppress-recovery --test-json-schema --underlay --verbose --warning-exit-0 --with-images --compression-level --jpeg-quality --encryption-file-password --force-version --ii-min-bytes --json-object --keep-files-open-threshold --min-version --oi-min-area --oi-min-height --oi-min-width --password --remove-attachment --rotate --show-attachment --show-object --copy-encryption --job-json-file --linearize-pass1 --password-file --update-from-json --json-stream-prefix --collate --split-pages --compress-streams --decode-level --flatten-annotations --json-key --json-stream-data --keep-files-open --normalize-content --object-streams --password-mode --remove-unreferenced-resources --stream-data --json --json-output"
    opts[pages]="--range --password --file"
    opts[encryption]="--user-password --owner-password --bits"
    opts[40-bit-encryption]="--extract --annotate --print --modify"
    opts[128-bit-encryption]="--cleartext-metadata --force-V4 --accessibility --extract --print --assemble --annotate --form --modify-other --modify --use-aes"
    opts[256-bit-encryption]="--cleartext-metadata --force-R5 --allow-insecure --accessibility --extract --print --assemble --annotate --form --modify-other --modify"
    opts[underlay/overlay]="--to --from --repeat --password --file"
    opts[attachment]="--replace --key --filename --creationdate --moddate --mimetype --description"
    opts[copy-attachment]="--prefix --password"
    opts[set-page-labels]=""
    _def help --version bare "none" ""
    _def help --copyright bare "none" ""
    _def help --show-crypto bare "none" ""
    _def help --job-json-help bare "none" ""
    _def help --zopfli bare "none" ""
    _def help --json-help opt "1 2 latest" ""
    _def global --no-default-limits bare "none" ""
    _def global --parser-max-container-size req "none" ""
    _def global --parser-max-container-size-damaged req "none" ""
    _def global --parser-max-errors req "none" ""
    _def global --parser-max-nesting req "none" ""
    _def global --max-stream-filters req "none" ""
    _def main --add-attachment bare "none" "attachment"
    _def main --allow-weak-crypto bare "none" ""
    _def main --check bare "none" ""
    _def main --check-linearization bare "none" ""
    _def main --coalesce-contents bare "none" ""
    _def main --copy-attachments-from bare "none" "copy-attachment"
    _def main --decrypt bare "none" ""
    _def main --deterministic-id bare "none" ""
    _def main --empty bare "none" ""
    _def main --encrypt bare "none" "encryption"
    _def main --externalize-inline-images bare "none" ""
    _def main --filtered-stream-data bare "none" ""
    _def main --flatten-rotation bare "none" ""
    _def main --generate-appearances bare "none" ""
    _def main --global bare "none" ""
    _def main --ignore-xref-streams bare "none" ""
    _def main --is-encrypted bare "none" ""
    _def main --json-input bare "none" ""
    _def main --keep-inline-images bare "none" ""
    _def main --linearize bare "none" ""
    _def main --list-attachments bare "none" ""
    _def main --newline-before-endstream bare "none" ""
    _def main --no-original-object-ids bare "none" ""
    _def main --no-warn bare "none" ""
    _def main --optimize-images bare "none" ""
    _def main --overlay bare "none" "underlay/overlay"
    _def main --pages bare "none" "pages"
    _def main --password-is-hex-key bare "none" ""
    _def main --preserve-unreferenced bare "none" ""
    _def main --preserve-unreferenced-resources bare "none" ""
    _def main --progress bare "none" ""
    _def main --qdf bare "none" ""
    _def main --raw-stream-data bare "none" ""
    _def main --recompress-flate bare "none" ""
    _def main --remove-acroform bare "none" ""
    _def main --remove-info bare "none" ""
    _def main --remove-metadata bare "none" ""
    _def main --remove-page-labels bare "none" ""
    _def main --remove-structure bare "none" ""
    _def main --replace-input bare "none" ""
    _def main --report-memory-usage bare "none" ""
    _def main --requires-password bare "none" ""
    _def main --remove-restrictions bare "none" ""
    _def main --set-page-labels bare "none" "set-page-labels"
    _def main --show-encryption bare "none" ""
    _def main --show-encryption-key bare "none" ""
    _def main --show-linearization bare "none" ""
    _def main --show-npages bare "none" ""
    _def main --show-pages bare "none" ""
    _def main --show-xref bare "none" ""
    _def main --static-aes-iv bare "none" ""
    _def main --static-id bare "none" ""
    _def main --suppress-password-recovery bare "none" ""
    _def main --suppress-recovery bare "none" ""
    _def main --test-json-schema bare "none" ""
    _def main --underlay bare "none" "underlay/overlay"
    _def main --verbose bare "none" ""
    _def main --warning-exit-0 bare "none" ""
    _def main --with-images bare "none" ""
    _def main --compression-level req "none" ""
    _def main --jpeg-quality req "none" ""
    _def main --encryption-file-password req "none" ""
    _def main --force-version req "none" ""
    _def main --ii-min-bytes req "none" ""
    _def main --json-object req "none" ""
    _def main --keep-files-open-threshold req "none" ""
    _def main --min-version req "none" ""
    _def main --oi-min-area req "none" ""
    _def main --oi-min-height req "none" ""
    _def main --oi-min-width req "none" ""
    _def main --password req "none" ""
    _def main --remove-attachment req "none" ""
    _def main --rotate req "none" ""
    _def main --show-attachment req "none" ""
    _def main --show-object req "none" ""
    _def main --copy-encryption req "file" ""
    _def main --job-json-file req "file" ""
    _def main --linearize-pass1 req "file" ""
    _def main --password-file req "file" ""
    _def main --update-from-json req "file" ""
    _def main --json-stream-prefix req "file" ""
    _def main --collate opt "none" ""
    _def main --split-pages opt "none" ""
    _def main --compress-streams req "y n" ""
    _def main --decode-level req "none generalized specialized all" ""
    _def main --flatten-annotations req "all print screen" ""
    _def main --json-key req "acroform attachments encrypt objectinfo objects outlines pagelabels pages qpdf" ""
    _def main --json-stream-data req "none inline file" ""
    _def main --keep-files-open req "y n" ""
    _def main --normalize-content req "y n" ""
    _def main --object-streams req "disable preserve generate" ""
    _def main --password-mode req "bytes hex-bytes unicode auto" ""
    _def main --remove-unreferenced-resources req "auto yes no" ""
    _def main --stream-data req "compress preserve uncompress" ""
    _def main --json opt "1 2 latest" ""
    _def main --json-output opt "2 latest" ""
    _def pages --range req "none" ""
    _def pages --password req "none" ""
    _def pages --file req "file" ""
    _def encryption --user-password req "none" ""
    _def encryption --owner-password req "none" ""
    _def encryption --bits req "40 128 256" "@value"
    _def 40-bit-encryption --extract req "y n" ""
    _def 40-bit-encryption --annotate req "y n" ""
    _def 40-bit-encryption --print req "y n" ""
    _def 40-bit-encryption --modify req "y n" ""
    _def 128-bit-encryption --cleartext-metadata bare "none" ""
    _def 128-bit-encryption --force-V4 bare "none" ""
    _def 128-bit-encryption --accessibility req "y n" ""
    _def 128-bit-encryption --extract req "y n" ""
    _def 128-bit-encryption --print req "full low none" ""
    _def 128-bit-encryption --assemble req "y n" ""
    _def 128-bit-encryption --annotate req "y n" ""
    _def 128-bit-encryption --form req "y n" ""
    _def 128-bit-encryption --modify-other req "y n" ""
    _def 128-bit-encryption --modify req "all annotate form assembly none" ""
    _def 128-bit-encryption --use-aes req "y n" ""
    _def 256-bit-encryption --cleartext-metadata bare "none" ""
    _def 256-bit-encryption --force-R5 bare "none" ""
    _def 256-bit-encryption --allow-insecure bare "none" ""
    _def 256-bit-encryption --accessibility req "y n" ""
    _def 256-bit-encryption --extract req "y n" ""
    _def 256-bit-encryption --print req "full low none" ""
    _def 256-bit-encryption --assemble req "y n" ""
    _def 256-bit-encryption --annotate req "y n" ""
    _def 256-bit-encryption --form req "y n" ""
    _def 256-bit-encryption --modify-other req "y n" ""
    _def 256-bit-encryption --modify req "all annotate form assembly none" ""
    _def underlay/overlay --to req "none" ""
    _def underlay/overlay --from req "none" ""
    _def underlay/overlay --repeat req "none" ""
    _def underlay/overlay --password req "none" ""
    _def underlay/overlay --file req "file" ""
    _def attachment --replace bare "none" ""
    _def attachment --key req "none" ""
    _def attachment --filename req "none" ""
    _def attachment --creationdate req "none" ""
    _def attachment --moddate req "none" ""
    _def attachment --mimetype req "none" ""
    _def attachment --description req "none" ""
    _def copy-attachment --prefix req "none" ""
    _def copy-attachment --password req "none" ""
    _def help --help opt "--accessibility --add-attachment --allow-insecure --allow-weak-crypto --annotate --assemble --bits --check --check-linearization --cleartext-metadata --coalesce-contents --collate --completion-bash --completion-zsh --compress-streams --compression-level --copy-attachments-from --copy-encryption --copyright --creationdate --decode-level --decrypt --description --deterministic-id --empty --encrypt --encryption-file-password --externalize-inline-images --extract --file --filename --filtered-stream-data --flatten-annotations --flatten-rotation --force-R5 --force-V4 --force-version --form --from --generate-appearances --global --help --ignore-xref-streams --ii-min-bytes --is-encrypted --job-json-file --job-json-help --jpeg-quality --json --json-help --json-input --json-key --json-object --json-output --json-stream-data --json-stream-prefix --keep-files-open --keep-files-open-threshold --keep-inline-images --key --linearize --linearize-pass1 --list-attachments --max-stream-filters --mimetype --min-version --moddate --modify --modify-other --newline-before-endstream --no-default-limits --no-original-object-ids --no-warn --normalize-content --object-streams --oi-min-area --oi-min-height --oi-min-width --optimize-images --overlay --owner-password --pages --parser-max-container-size --parser-max-container-size-damaged --parser-max-errors --parser-max-nesting --password --password-file --password-is-hex-key --password-mode --prefix --preserve-unreferenced --preserve-unreferenced-resources --print --progress --qdf --range --raw-stream-data --recompress-flate --remove-acroform --remove-attachment --remove-info --remove-metadata --remove-page-labels --remove-restrictions --remove-structure --remove-unreferenced-resources --repeat --replace --replace-input --report-memory-usage --requires-password --rotate --set-page-labels --show-attachment --show-crypto --show-encryption --show-encryption-key --show-linearization --show-npages --show-object --show-pages --show-xref --split-pages --static-aes-iv --static-id --stream-data --suppress-password-recovery --suppress-recovery --test-json-schema --to --underlay --update-from-json --use-aes --user-password --verbose --version --warning-exit-0 --with-images --zopfli add-attachment advanced-control all attachments completion copy-attachments encryption exit-status general global help inspection json modification overlay-underlay page-ranges page-selection pdf-dates testing transformation usage" ""
    _def help --completion-bash bare "none" ""
    _def help --completion-zsh bare "none" ""
    vnext[encryption.--bits.40]=40-bit-encryption
    vnext[encryption.--bits.128]=128-bit-encryption
    vnext[encryption.--bits.256]=256-bit-encryption
    # END GENERATED

    unfunction _def

    # ---- Walk prior words to determine active table -----------------------
    # $words is the full command line, already unquoted by zsh.
    local cur_table=main merge_help=1
    integer i
    local w opt val key nt
    for (( i=2; i<CURRENT; i++ )); do
        w=${words[i]}
        if [[ $w == "--" ]]; then
            cur_table=main; merge_help=0; continue
        fi
        if [[ $w == --*=* ]]; then
            opt=${w%%=*}; val=${w#*=}
        elif [[ $w == --* ]]; then
            opt=$w; val=""
        else
            merge_help=0; continue
        fi
        key="$cur_table.$opt"
        if [[ -z ${arity[$key]-} ]] && (( merge_help )); then
            key="help.$opt"
        fi
        merge_help=0
        [[ -z ${arity[$key]-} ]] && continue
        nt=${nexttab[$key]}
        if [[ $nt == "@value" ]]; then
            [[ -n ${vnext[$key.$val]-} ]] && cur_table=${vnext[$key.$val]}
        elif [[ -n $nt ]]; then
            cur_table=$nt
        fi
    done
    (( CURRENT == 2 )) && merge_help=1

    local cur=${words[CURRENT]}

    # ---- Dispatch ---------------------------------------------------------
    if [[ $cur == --*=* ]]; then
        opt=${cur%%=*}; val=${cur#*=}
        key="$cur_table.$opt"
        if [[ -z ${arity[$key]-} ]] && (( merge_help )); then
            key="help.$opt"
        fi
        [[ -z ${arity[$key]-} ]] && return 0
        local vs=${values[$key]}
        case $vs in
            none) return 0 ;;
            file)
                # compset -P strips the --opt= from the completion context
                # so _files sees only the value portion. _files handles
                # shell quoting of paths with spaces/specials correctly.
                compset -P '*='
                _files
                return 0
                ;;
            *)
                compset -P '*='
                local -a choices=( ${=vs} )
                compadd -a choices
                return 0
                ;;
        esac
    elif [[ $cur == --* || -z $cur ]]; then
        local all=${opts[$cur_table]}
        (( merge_help )) && all+=" ${opts[help]}"
        local -a bare_opts req_opts opt_opts
        local o k
        for o in ${=all}; do
            k="$cur_table.$o"
            [[ -z ${arity[$k]-} ]] && k="help.$o"
            case ${arity[$k]} in
                bare) bare_opts+=( $o ) ;;
                req)  req_opts+=( $o ) ;;
                opt)  opt_opts+=( $o ) ;;
            esac
        done
        (( $#bare_opts )) && compadd -- $bare_opts
        (( $#req_opts )) && compadd -S '=' -- $req_opts
        # For opt arity, offer both forms explicitly (matching bash): the
        # bare "--opt" and "--opt=" with a removable-on-space '=' suffix.
        (( $#opt_opts )) && compadd -- $opt_opts
        (( $#opt_opts )) && compadd -qS '=' -- $opt_opts
        # If the cur is entirely empty and we're at a positional slot,
        # also offer file completion.
        [[ -z $cur ]] && _files
        return 0
    else
        _files
        return 0
    fi
}

if (( $+functions[compdef] )); then
    compdef _qpdf qpdf
fi
