# astra-subscription(1) completion                                       -*- shell-script -*-

_astra_subscription() {

    local cur prev words cword
    _init_completion || return

    local commands="register unregister attach status clear import export remove config repos health"
    local register_opts="--username --password --organization --server-url --force --auto-attach"
    local attach_opts="--pool-id"
    local status_opts="--consumer --product-os --product-id --list"
    local status_list_opts="--available --pool-id"
    local import_opts="--file"
    local export_opts="--file --product-id"
    local remove_opts="--serial --pool-id"
    local config_opts="--list --get --set --validate"
    local repos_opts="--enable --enable-all --disable --disable-all --list --update-cert"
    local repos_list_opts="--available --enabled --disabled"

    if [[ ${words[0]} == "astra-subscription" && $cword == 1 ]]; then
        COMPREPLY=($(compgen -W "${commands} --help --version --verbose --json" -- "${cur}"))
        return
    fi

    case ${words[1]} in
        register)
            case $prev in
                -[!-]*u|-u|--username|-[!-]*p|-p|--password|-[!-]*o|-o|--organization|-[!-]*s|-s|--server-url)
                    return
                    ;;
                *)
                    COMPREPLY=($(compgen -W "${register_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        attach)
            case $prev in
                -[!-]*p|-p|--pool-id)
                    return
                    ;;
                *)
                    COMPREPLY=($(compgen -W "${attach_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        status)
            case $prev in
                -[!-]*c|-c|--consumer|-[!-]*o|-o|--product-os|-[!-]*i|-i|--product-id)
                    return
                    ;;
                -[!-]*l*|-l*|--list)
                    case $prev in
                        -[!-]*p|-p|--pool-id)
                            return
                            ;;
                        *)
                            COMPREPLY=($(compgen -W "${status_list_opts}" -- "${cur}"))
                            ;;
                    esac
                    ;;
                *)
                    COMPREPLY=($(compgen -W "${status_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        repos)
            case $prev in
                -[!-]*e|-e|--enable|-[!-]*n|-n|--enable-all|-[!-]*d|-d|--disable|-[!-]*i|-i|--disable-all)
                    return
                    ;;
                -[!-]*l|-l|--list)
                    case $prev in
                        -[!-]*a|-a|--available|--enabled|--disabled)
                            return
                            ;;
                        *)
                            COMPREPLY=($(compgen -W "${repos_list_opts}" -- "${cur}"))
                            ;;
                    esac
                    ;;
                *)
                    COMPREPLY=($(compgen -W "${repos_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        import)
            case $prev in
                -[!-]*f|-f|--file)
                    COMPREPLY=($(compgen -f -- "${cur}"))
                    ;;
                *)
                    COMPREPLY=($(compgen -W "${import_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        export)
            case $prev in
                -[!-]*i|-i|--product-id)
                    return
                    ;;
                -[!-]*f|-f|--file)
                    COMPREPLY=($(compgen -f -- "${cur}"))
                    ;;
                *)
                    COMPREPLY=($(compgen -W "${export_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        remove)
            case $prev in
                -[!-]*s|-s|--serial|-[!-]*p|-p|--pool-id)
                    return
                    ;;
                *)

                    COMPREPLY=($(compgen -W "${remove_opts} --help --verbose" -- "${cur}"))
                    ;;
            esac
            ;;
        config)
            if [[ $cword == 2 ]]; then
                COMPREPLY=($(compgen -W "${config_opts} --help --verbose" -- "${cur}"))
                return
            fi

            case ${words[2]} in
                -[!-]*l|-l|--list|-[!-]*g|-g|--get|-[!-]*s|-s|--set|-[!-]*a|-a|--validate)
                    return
                    ;;
            esac
            ;;
        *)
            COMPREPLY=($(compgen -W "--help --verbose --json" -- "${cur}"))
            ;;
    esac
}

complete -o nospace -F _astra_subscription astra-subscription

