#
# Bash completion file for PicoScenes
#

argument_name='
--plugin-dir
-d
--display-level
--no-hp
-i
--interface
-h
--help
-q
--quit
--format
--cbw
--mcs
--sts
--ess
--gi
--coding
--extended-range
--high-doppler
--ifs
--precoding-config
--pul-key
--pul-key-file
--show-license
--channel
--control
--rx-cbw
--freq
--rate
--txcm
--rxcm
--txpower
--agc
--rx-gain
--source-address-filter
--destination-address-filter
--plot
--plot-engine
--freq
--rate
--tx-resample-ratio
--rx-resample-ratio
--clock-source
--tx-cfo
--tx-sfo
--rx-cfo
--rx-sfo
--precise-sfo
--master-clock-rate
--tx-channel
--rx-channel
--rx-cbw
--tx-ant
--rx-ant
--txpower
--rx-gain
--filter-bw
--tx-to-file
--tx-only-to-file
--tx-from-file
--tx-from-file-delay
--rx-to-file
--rx-from-file
--rx-sensitivity
--rx-cp-offset
--tx-iq-mismatch
--rx-iq-mismatch
--enable-1ant-tx-4-extra-sounding
--enable-loopback
--source-address-filter
--destination-address-filter
--plot
--plot-engine
--mode
--output
--target-mac-address
--5300
--cf
--sf
--repeat
--delay
--delayed-start
--injector-content
--ack-type
--ack-mcs
--ack-sts
--ack-cbw
--ack-gi
--forward-to
'

declare -A argument_value_map
argument_value_map=(
    ["-d"]="veryverbose vv verbose v debug detail trace info warning error mute"
    ["--display-level"]="veryverbose vv verbose v debug detail trace info warning error mute"
    ["--format"]="nonHT HT VHT HESU"
    ["--cbw"]="20 40 80 160"
    ["--mcs"]="0 1 2 3 4 5 6 7 8 9 10 11"
    ["--sts"]="1 2 3 4"
    ["--ess"]="0 1 2 3"
    ["--gi"]="400 800 1600 3200"
    ["--coding"]="LDPC BCC"
    ["--high-doppler"]="10 20"
    ["--plot"]="absolute log"
    ["--plot-engine"]="qt x11 wxt"
    ["--clock-source"]="internal external"
    ["--rx-cbw"]="20 40 80 160"
    ["--tx-ant"]="TX/RX CAL"
    ["--rx-ant"]="TX/RX RX2 CAL"
    ["--mode"]="injector logger initiator responder"
    ["--injector-content"]="full header ndp"
    ["--ack-type"]="full csi extra header"
    ["--ack-gi"]="400 800 1600 3200"
)

_picoscenes_complete()
{
    local key value
    COMPREPLY=()
    local key="${COMP_WORDS[COMP_CWORD]}"

    if [[ $(($COMP_CWORD%2)) == 1 ]]; then
        # Completion of argument names
        COMPREPLY=( $(compgen -W '${argument_name}' -- "${key}" ) )
    else
        # Completion of argument value
        value=${COMP_WORDS[COMP_CWORD-1]}
        if [[ -n ${argument_value_map[${value}]} ]]; then
            COMPREPLY=( $(compgen -W '${argument_value_map[${value}]}' -- ${key} ) )
        fi
    fi
}
complete -F _picoscenes_complete PicoScenes