#!/bin/zsh
#
# THIS FILE IS GENERATED. DO NOT EDIT.
#
# Completion strategy (fastest-first):
#   1. Shortcuts    — single-character aliases resolved before any other logic.
#   2. Top-level    — all known subcommands when no subcommand has been typed yet.
#   3. Flags        — matched when the current token starts with '-'.
#   3.5. Option values  — static values for known flags (e.g. --to sqlite).
#   3.6. Comma values   — comma-separable list (e.g. cds add ai,hana).
#   4. File positionals — files/dirs for subcommands that take a path argument.
#   4.6. String positionals — fixed word list (e.g. cds help <tab>).
#   5. Dynamic fallback — calls 'cds completion' for anything not covered above.
#
# Zsh uses $words (1-based token array) and $CURRENT (index of cursor token).
# Completions are added with compadd instead of bash's COMPREPLY.
# 'case ... esac && return' exits the function when a case arm matched.

CDS_COMMAND="cds"

_completeCds() {
    local current="${words[CURRENT]}"
    local previous="${words[CURRENT-1]}"
    # The subcommand is always the second token (index 2 in 1-based zsh arrays).
    local cmd="${words[2]}"
    # Step 1: resolve single-character shortcuts to their canonical command name.
    case "$cmd" in
        i) cmd=init ;;
        a) cmd=add ;;
        y) cmd=bind ;;
        m) cmd=import ;;
        c) cmd=compile ;;
        p) cmd=parse ;;
        s) cmd=serve ;;
        w) cmd=watch ;;
        e) cmd=env ;;
        b) cmd=build ;;
        d) cmd=deploy ;;
        l) cmd=login ;;
        o) cmd=logout ;;
        t) cmd=test ;;
        v) cmd=version ;;
        h) cmd=help ;;
        r) cmd=repl ;;
    esac

    # Step 2: top-level — offer all known subcommands when no subcommand has been
    # typed yet ($words is 1-based; ≤ 2 means "cds <cursor>").
    if [[ "${#words[@]}" -le 2 ]]; then
        compadd -S '' -- "add" "bind" "bindings" "build" "compile" "completion" "debug" "deploy" "env" "eval" "export" "gen" "help" "import" "init" "inspect" "lint" "login" "logout" "minify" "mock" "parse" "pull" "push" "repl" "run" "serve" "subscribe" "test" "unsubscribe" "up" "upgrade" "upgrade-tenant" "version" "watch"
        return
    fi

    # Step 3: flag/option completion — only triggered when the token starts with '-'.
    # 'case ... esac && return' exits the function when a case arm matched.
    if [[ "$current" == -* ]]; then
        case "$cmd" in
        add) compadd -S '' -- "--base" "--cdm" "--cloudevents" "--composition-records" "--content-type" "--data:for" "--dry" "--filter" "--for" "--for-app" "--force" "--into" "--java:mvn" "--js" "--keys-only" "--out" "--package" "--plan" "--records" "--sap" "--shell" "--ts" "--unified-runtime" "--with-telemetry" "--workspace" "--y" ;;
        bind) compadd -S '' -- "--credentials" "--exec" "--for" "--kind" "--no-create-service-key" "--on" "--out" "--output-file" "--to" "--to-app-services" ;;
        bindings) compadd -S '' -- "--as" ;;
        build) compadd -S '' -- "--dest" "--for" "--log-level" "--no-clean" "--no-ws-pack" "--options-model" "--opts" "--project" "--src" "--ws" "--ws-pack" ;;
        compile) compadd -S '' -- "--all" "--asyncapi:merged" "--beta" "--clean" "--conceptual" "--dest" "--dialect" "--docs" "--files" "--flavor" "--for" "--from" "--lang" "--locations" "--log-level" "--min" "--odata-version" "--openapi:config-file" "--openapi:diagram" "--openapi:servers" "--openapi:url" "--parse" "--plain" "--resolved" "--service" "--sort" "--sources" "--sql-dialect" "--to" ;;
        completion) compadd -S '' -- "--add" "--curr" "--line" "--prev" "--profile" "--remove" "--shell" ;;
        debug) compadd -S '' -- "--cf" "--force" "--host" "--k8s" "--kyma" "--no-devtools" "--port" ;;
        deploy) compadd -S '' -- "--auto-undeploy" "--delta-from" "--dry" "--for" "--model-only" "--no-build" "--no-save" "--on" "--out" "--resolve-bindings" "--script" "--store-credentials" "--to" "--tunnel-address" "--vcap-file" "--with-auto-schema-evolution" "--with-mocks" "--xdry" ;;
        env) compadd -S '' -- "--for" "--json" "--keys" "--list" "--mocked" "--process-env" "--properties" "--raw" "--resolve-bindings" "--sources" ;;
        eval) compadd -S '' -- "--quiet" "--silent" ;;
        export) compadd -S '' -- "--artifact" "--as" "--cleanse" "--data" "--debug" "--dry" "--for" "--from" "--inspect" "--keep" "--mvn" "--plugin" "--reuse" "--services" "--skip" "--texts" "--to" ;;
        import) compadd -S '' -- "--as" "--asyncapi" "--config" "--data-product" "--dependencies" "--destination" "--dry" "--edmx" "--for" "--force" "--from" "--group" "--include-namespaces" "--into-namespace" "--keep-namespace" "--name" "--no-copy" "--no-save" "--odata" "--odata-v2-annotations" "--openapi" "--out" "--resolve-bindings" "--rfc" "--services" ;;
        init) compadd -S '' -- "--add" "--base" "--force" "--java" "--java:mvn" "--java:package" "--lint:custom" "--lint:custom:example" "--no-db" "--nodejs" "--verbose" ;;
        inspect) compadd -S '' -- "--kind" "--list" "--stats" ;;
        lint) compadd -S '' -- "--cache" "--cache-file" "--cache-location" "--cache-strategy" "--color" "--concurrency" "--config" "--debug" "--env-info" "--exit-on-fatal-error" "--ext" "--fix" "--fix-dry-run" "--fix-type" "--flag" "--format" "--global" "--help" "--ignore-pattern" "--init" "--inspect-config" "--max-warnings" "--mcp" "--no-color" "--no-config-lookup" "--no-error-on-unmatched-pattern" "--no-ignore" "--no-inline-config" "--no-warn-ignored" "--output-file" "--parser" "--parser-options" "--pass-on-no-patterns" "--pass-on-unpruned-suppressions" "--plugin" "--print-config" "--prune-suppressions" "--quiet" "--report-unused-disable-directives" "--report-unused-disable-directives-severity" "--report-unused-inline-configs" "--rule" "--stats" "--stdin" "--stdin-filename" "--suppress-all" "--suppress-rule" "--suppressions-location" "--version" ;;
        login) compadd -S '' -- "--app-tid" "--client" "--mtls" "--no-browser" "--passcode" "--plain" "--port" "--save-refresh-token" "--subdomain" "--user" ;;
        logout) compadd -S '' -- "--clear-invalid" "--delete-settings" "--subdomain" "--url" ;;
        minify) compadd -S '' -- "--cleanse" "--debug" "--dry" "--inspect" "--keep" "--skip" ;;
        mock) compadd -S '' -- "--at" "--from" "--in-memory" "--in-memory?" "--mocked" "--port" "--project" "--projects" "--resolve-bindings" "--service" "--to" "--watch" "--with" "--with-bindings" "--with-mocks" "--with-mtx" "--workers" ;;
        parse) compadd -S '' -- "--all" "--asyncapi:merged" "--beta" "--clean" "--conceptual" "--dest" "--dialect" "--docs" "--files" "--flavor" "--for" "--from" "--lang" "--locations" "--log-level" "--min" "--odata-version" "--openapi:config-file" "--openapi:diagram" "--openapi:servers" "--openapi:url" "--parse" "--plain" "--resolved" "--service" "--sort" "--sources" "--sql-dialect" "--to" ;;
        pull) compadd -S '' -- "--client" "--from" "--mtls" "--passcode" "--subdomain" "--user" ;;
        push) compadd -S '' -- "--async" "--client" "--mtls" "--passcode" "--subdomain" "--sync" "--to" "--user" ;;
        repl) compadd -S '' -- "--ql" "--run" "--use" ;;
        run) compadd -S '' -- "--at" "--from" "--in-memory" "--in-memory?" "--mocked" "--port" "--project" "--projects" "--resolve-bindings" "--service" "--to" "--watch" "--with" "--with-bindings" "--with-mocks" "--with-mtx" "--workers" ;;
        serve) compadd -S '' -- "--at" "--from" "--in-memory" "--in-memory?" "--mocked" "--port" "--project" "--projects" "--resolve-bindings" "--service" "--to" "--watch" "--with" "--with-bindings" "--with-mocks" "--with-mtx" "--workers" ;;
        subscribe) compadd -S '' -- "--body" "--local" "--resolve-bindings" "--to" "--user" ;;
        test) compadd -S '' -- "--exclude" "--failed" "--files" "--include" "--list" "--passed" "--quiet" "--recent" "--silent" "--timeout" "--unmute" "--verbose" "--workers" ;;
        unsubscribe) compadd -S '' -- "--from" "--local" "--resolve-bindings" "--user" ;;
        up) compadd -S '' -- "--namespace" "--overlay" "--to" ;;
        upgrade) compadd -S '' -- "--at" "--fix" "--local" "--report" "--resolve-bindings" "--user" ;;
        upgrade-tenant) compadd -S '' -- "--at" "--local" "--resolve-bindings" "--user" ;;
        version) compadd -S '' -- "--abs" "--all" "--depth" "--info" "--json" "--markdown" "--omit" ;;
        watch) compadd -S '' -- "--debug" "--exclude" "--experimental-hot-reload" "--ext" "--in-memory" "--in-memory?" "--include" "--inspect" "--inspect-brk" "--livereload" "--open" "--port" "--with-mocks" "--with-mtx" ;;
        esac && return
    fi

    # Step 3.5: option-value completion — triggered when the previous word is a known option.
    case "$cmd" in
        bind)
            case "$previous" in
            --on) compadd -S '' -- "cf" "k8s" "kyma" ; return ;;
            --for) compadd -S '' -- "development" "hybrid" "production" ; return ;;
            --out) compstate[nomatches]='' ; _path_files ; return ;;
            --output-file) compstate[nomatches]='' ; _path_files ; return ;;
            --credentials) compstate[nomatches]='' ; _path_files -g '*.json' ; return ;;
            esac ;;
        bindings)
            case "$previous" in
            --as) compadd -S '' -- "json" "yaml" ; return ;;
            esac ;;
        build)
            case "$previous" in
            --for) compadd -S '' -- "hana" "helm" "java" "mtx" "mtx-extension" "mtx-sidecar" "nodejs" ; return ;;
            --log-level) compadd -S '' -- "debug" "error" "info" "warn" ; return ;;
            --project) compstate[nomatches]='' ; _files -/ ; return ;;
            --dest) compstate[nomatches]='' ; _files -/ ; return ;;
            --src) compstate[nomatches]='' ; _files -/ ; return ;;
            --options-model) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
            esac ;;
        compile)
            case "$previous" in
            --from) compadd -S '' -- "cdl" "json" "yaml" ; return ;;
            --to) compadd -S '' -- "asyncapi" "cdl" "edm" "edmx" "edmx-v2" "edmx-v4" "hana" "hdbtable" "json" "openapi" "sql" "xsuaa" "yml" ; return ;;
            --for) compadd -S '' -- "odata" "sql" ; return ;;
            --dialect) compadd -S '' -- "h2" "hana" "postgres" "sqlite" ; return ;;
            --sql-dialect) compadd -S '' -- "h2" "hana" "postgres" "sqlite" ; return ;;
            --log-level) compadd -S '' -- "debug" "error" "info" "warn" ; return ;;
            --odata-version) compadd -S '' -- "4.0" "4.01" ; return ;;
            --flavor) compadd -S '' -- "files" "inferred" "parsed" "sources" "xtended" ; return ;;
            --service) compadd -S '' -- "all" ; return ;;
            --lang) compadd -S '' -- "all" ; return ;;
            --dest) compstate[nomatches]='' ; _files -/ ; return ;;
            --openapi:config-file) compstate[nomatches]='' ; _path_files -g '*.json' ; return ;;
            esac ;;
        completion)
            case "$previous" in
            --shell) compadd -S '' -- "bash" "fish" "gitbash" "ps" "zsh" ; return ;;
            esac ;;
        deploy)
            case "$previous" in
            --to) compadd -S '' -- "hana" "sqlite" ; return ;;
            --on) compadd -S '' -- "cf" "k8s" "kyma" ; return ;;
            --for) compadd -S '' -- "development" "hybrid" "production" ; return ;;
            --out) compstate[nomatches]='' ; _path_files ; return ;;
            --vcap-file) compstate[nomatches]='' ; _path_files -g '*.json' ; return ;;
            --delta-from) compstate[nomatches]='' ; _path_files -g '*.json' ; return ;;
            esac ;;
        env)
            case "$previous" in
            --for) compadd -S '' -- "development" "hybrid" "production" ; return ;;
            esac ;;
        export)
            case "$previous" in
            --as) compadd -S '' -- "cdl" "csn" ; return ;;
            --for) compadd -S '' -- "mvn" "npm" ; return ;;
            --services) compadd -S '' -- "all" ; return ;;
            --from) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
            --to) compstate[nomatches]='' ; _files -/ ; return ;;
            esac ;;
        import)
            case "$previous" in
            --from) compadd -S '' -- "asyncapi" "edmx" "openapi" ; return ;;
            --as) compadd -S '' -- "cds" "csn" "json" ; return ;;
            --for) compadd -S '' -- "development" "hybrid" "production" ; return ;;
            --out) compstate[nomatches]='' ; _files -/ ; return ;;
            --dependencies) compstate[nomatches]='' ; _path_files ; return ;;
            esac ;;
        init)
            case "$previous" in
            --java:package) compstate[nomatches]='' ; _files -/ ; return ;;
            --base) compstate[nomatches]='' ; _files -/ ; return ;;
            esac ;;
        inspect)
            case "$previous" in
            --kind) compadd -S '' -- "aspect" "entity" "service" "type" ; return ;;
            --list) compadd -S '' -- "all" "associations" "compositions" "elements" "ids" "keys" "names" "sources" ; return ;;
            esac ;;
        parse)
            case "$previous" in
            --from) compadd -S '' -- "cdl" "json" "yaml" ; return ;;
            --to) compadd -S '' -- "asyncapi" "cdl" "edm" "edmx" "edmx-v2" "edmx-v4" "hana" "hdbtable" "json" "openapi" "sql" "xsuaa" "yml" ; return ;;
            --for) compadd -S '' -- "odata" "sql" ; return ;;
            --dialect) compadd -S '' -- "h2" "hana" "postgres" "sqlite" ; return ;;
            --sql-dialect) compadd -S '' -- "h2" "hana" "postgres" "sqlite" ; return ;;
            --log-level) compadd -S '' -- "debug" "error" "info" "warn" ; return ;;
            --odata-version) compadd -S '' -- "4.0" "4.01" ; return ;;
            --flavor) compadd -S '' -- "files" "inferred" "parsed" "sources" "xtended" ; return ;;
            --service) compadd -S '' -- "all" ; return ;;
            --lang) compadd -S '' -- "all" ; return ;;
            --dest) compstate[nomatches]='' ; _files -/ ; return ;;
            --openapi:config-file) compstate[nomatches]='' ; _path_files -g '*.json' ; return ;;
            esac ;;
        repl)
            case "$previous" in
            --use) compadd -S '' -- "entities" "ql" "services" "xl" ; return ;;
            --run) compstate[nomatches]='' ; _files -/ ; return ;;
            -r) compstate[nomatches]='' ; _files -/ ; return ;;
            esac ;;
        run)
            case "$previous" in
            --to) compadd -S '' -- "fiori" "odata" "rest" ; return ;;
            --service) compadd -S '' -- "all" ; return ;;
            --from) compstate[nomatches]='' ; _files -/ ; return ;;
            -f) compstate[nomatches]='' ; _files -/ ; return ;;
            --with) compstate[nomatches]='' ; _files -/ ; return ;;
            esac ;;
        serve)
            case "$previous" in
            --to) compadd -S '' -- "fiori" "odata" "rest" ; return ;;
            --service) compadd -S '' -- "all" ; return ;;
            --from) compstate[nomatches]='' ; _files -/ ; return ;;
            -f) compstate[nomatches]='' ; _files -/ ; return ;;
            --with) compstate[nomatches]='' ; _files -/ ; return ;;
            esac ;;
        up)
            case "$previous" in
            --to) compadd -S '' -- "cf" "k8s" "kyma" ; return ;;
            --overlay) compstate[nomatches]='' ; _path_files -g '*.mtaext' ; return ;;
            esac ;;
        version)
            case "$previous" in
            --omit) compadd -S '' -- "dev" "optional" "peer" ; return ;;
            esac ;;
        watch)
            case "$previous" in
            --to) compadd -S '' -- "fiori" "odata" "rest" ; return ;;
            -2) compadd -S '' -- "fiori" "odata" "rest" ; return ;;
            --experimental-hot-reload) compadd -S '' -- "false" "true" ; return ;;
            --livereload) compadd -S '' -- "false" ; return ;;
            --from) compstate[nomatches]='' ; _files -/ ; return ;;
            -f) compstate[nomatches]='' ; _files -/ ; return ;;
            --with) compstate[nomatches]='' ; _files -/ ; return ;;
            -w) compstate[nomatches]='' ; _files -/ ; return ;;
            --include) compstate[nomatches]='' ; _files -/ ; return ;;
            --exclude) compstate[nomatches]='' ; _files -/ ; return ;;
            esac ;;

    esac

    # Step 3.6: comma-separated option-value completion.
    case "$cmd" in
        add)
            case "$previous" in
            *)
                [[ "$previous" == -* ]] && return
                local -a _used=("${(s:,:)current}")
                local prefix="${(j:,:)_used[1,-2]}" partial="${_used[-1]}"
                [[ -n "$prefix" ]] && prefix="$prefix,"
                local -a _all=("ai" "ams" "app-frontend" "application-logging" "approuter" "attachments" "audit-logging" "cf-manifest" "cjs" "cloud-logging" "completion" "connectivity" "console" "data" "destination" "dynatrace" "enterprise-messaging" "enterprise-messaging-shared" "event-mesh" "event-mesh-shared" "extensibility" "extension" "file-based-messaging" "github-actions" "h2" "hana" "hana-serverless" "handler" "html5-repo" "http" "ias" "initial" "kafka" "kyma" "lint" "liquibase" "local-messaging" "malware-scanner" "mta" "mtx" "multitenancy" "notifications" "pipeline" "portal" "postgres" "react" "redis" "redis-messaging" "sample" "side-by-side-extensibility" "sqlite" "telemetry" "test" "tiny-sample" "toggles" "typer" "typescript" "ui5" "vue" "workzone" "workzone-standard" "xsuaa") _result=()
                for v in "${_all[@]}"; do
                    (( ${_used[(Ie)$v]} )) && continue
                    [[ "$v" == "$partial"* ]] && _result+=("$v")
                done
                compadd -p "$prefix" -S '' -- "${_result[@]}" ; return ;;
            esac ;;
        init)
            case "$previous" in
            --add)
                local -a _used=("${(s:,:)current}")
                local prefix="${(j:,:)_used[1,-2]}" partial="${_used[-1]}"
                [[ -n "$prefix" ]] && prefix="$prefix,"
                local -a _all=("ai" "ams" "app-frontend" "application-logging" "approuter" "attachments" "audit-logging" "cf-manifest" "cjs" "cloud-logging" "completion" "connectivity" "console" "data" "destination" "dynatrace" "enterprise-messaging" "enterprise-messaging-shared" "event-mesh" "event-mesh-shared" "extensibility" "extension" "file-based-messaging" "github-actions" "h2" "hana" "hana-serverless" "handler" "html5-repo" "http" "ias" "initial" "kafka" "kyma" "lint" "liquibase" "local-messaging" "malware-scanner" "mta" "mtx" "multitenancy" "notifications" "pipeline" "portal" "postgres" "react" "redis" "redis-messaging" "sample" "side-by-side-extensibility" "sqlite" "telemetry" "test" "tiny-sample" "toggles" "typer" "typescript" "ui5" "vue" "workzone" "workzone-standard" "xsuaa") _result=()
                for v in "${_all[@]}"; do
                    (( ${_used[(Ie)$v]} )) && continue
                    [[ "$v" == "$partial"* ]] && _result+=("$v")
                done
                compadd -p "$prefix" -S '' -- "${_result[@]}" ; return ;;
            esac ;;

    esac

    # Step 4: file-sentinel positionals — emit files and return.
    case "$cmd" in
        compile) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
        deploy) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
        export) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
        import) compstate[nomatches]='' ; _path_files -g '*.json *.xml *.edmx' ; return ;;
        inspect) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
        lint) compstate[nomatches]='' ; _path_files -g '*.js *.ts *.cds' -/ ; return ;;
        minify) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
        parse) compstate[nomatches]='' ; _path_files -g '*.cds *.json' -/ ; return ;;
        repl) compstate[nomatches]='' ; _files -/ ; return ;;
        run) compstate[nomatches]='' ; _files -/ ; return ;;
        serve) compstate[nomatches]='' ; _files -/ ; return ;;
        watch) compstate[nomatches]='' ; _files -/ ; return ;;
    esac

    # Step 4.6: string positionals (e.g. cds help <tab>) — return after matching.
    case "$cmd" in
        help) compadd -S '' -- "add" "bind" "bindings" "build" "compile" "completion" "debug" "deploy" "env" "eval" "export" "gen" "help" "import" "init" "inspect" "lint" "login" "logout" "minify" "mock" "parse" "pull" "push" "repl" "run" "serve" "subscribe" "test" "unsubscribe" "up" "upgrade" "upgrade-tenant" "version" "watch" ; return ;;
    esac && return

    # Step 5: dynamic fallback — calls 'cds completion' for subcommands whose arguments
    # cannot be determined statically (e.g. service names, model names, unknown flags).
    # Single-quoting $prev/$curr prevents bare word 'h' from being interpreted
    # as the 'help' shortcut by the completion handler before it is processed.
    # compadd -S '' suppresses the trailing space zsh normally appends after a completion.
    compadd -S '' -- $(${CDS_COMMAND} completion --shell zsh --prev "'${words[CURRENT-1]}'" --curr "'${words[CURRENT]}'" --line "'${words[*]}'")
}

# Register the completion function for the 'cds' command.
compdef _completeCds ${CDS_COMMAND}
