# shellcheck shell=bash disable=SC2154,2034
# This function is used to edit an existing alert
___x_cmd_shodan_alert_edit(){
    local X_help_cmd='x help -m shodan alert edit';   help:arg-null:parse
    shodan:arg:format:raw:json2app:all
    local id="$1"
    [ -n "$id" ]   ||  N=shodan M="Provide an alert ID" log:ret:64
    [ "$#" -gt 0 ] || N=shodan M="Provide an IP"        log:ret:64
    shift
    local x_=
    while [ "$#" -gt 0 ]; do
        case "$1" in
            [0-9]*) ___x_cmd_shodan_alert_edit___handle "$1"; shift     ;;
            *)      N=shodan M="Invalid IP: $1" log:ret:64              ;;
        esac
    done

    shodan:debug "json=$x_"
    set -- "-d '{ \"filters\": {\"ip\": [$x_]}}'"
    ___x_cmd_shodan_alert_edit___"$format" "$@"
}

___x_cmd_shodan_alert_edit___handle(){
    local ip="$1"
    local _ip=; local tmp=;
    if [ "$ip" = "${ip% *}" ]; then
        x_="${x_:+$x_,}\"$ip\""
    else
        while [ "$ip" != "${ip% *}" ]; do
            _ip="${ip%% *}" ; tmp="${ip#* }"
            x_="${x_:+$x_,}\"$_ip\""
            ip="$tmp"
        done
        x_="$x_,\"$ip\""
    fi
}

___x_cmd_shodan_alert_edit___app(){
    local data;     data="$( ___x_cmd_shodan_alert_edit___raw "$@" )"    || shodan:data:ret
    ___x_cmd_pipevar data       x j2y
}

___x_cmd_shodan_alert_edit___json(){
    local data;     data="$( ___x_cmd_shodan_alert_edit___raw "$@" )"    || shodan:data:ret
    ___x_cmd_pipevar data
}

___x_cmd_shodan_alert_edit___raw(){
    ___x_cmd_shodan_curl post "/shodan/alert/${id}" "$@"
}

