_dunstctl() {
    local opts cur prev
    _get_comp_words_by_ref cur prev
    COMPREPLY=()
    opts='action close close-all context count debug help history history-clear history-pop history-rm is-paused rule rules set-paused get-pause-level set-pause-level reload'

    case "$prev" in
        count) COMPREPLY=( $( compgen -W 'displayed history waiting' -- "$cur" ) )
            return ;;
        set-paused) COMPREPLY=( $( compgen -W 'true false toggle' -- "$cur" ) )
            return ;;
        history-pop|history-rm)
            COMPREPLY=( $( compgen -W "$(dunstctl history | jq -r '.data[][].id.data')" -- "$cur" ) )
            return ;;
        rule)
            COMPREPLY=( $( compgen -W "$(dunstctl rules --json | jq -r '.data[][].name.data')" -- "$cur" ) )
            return ;;
        rules)
            COMPREPLY=( $( compgen -W "--json" -- "$cur" ) )
            return ;;
    esac

    case "${COMP_WORDS[1]}" in
        rule) COMPREPLY=( $( compgen -W 'enable disable toggle' -- "$cur" ) )
            return ;;
    esac

    case "$cur" in
        *) COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) ;;
    esac
} && complete -F _dunstctl dunstctl

# ex: filetype=sh
