# shellcheck shell=dash disable=SC2154,2034
___x_cmd_shodan_alert_info(){
    local X_help_cmd='x help -m shodan alert info';   help:arg-null:parse
    shodan:arg:format:all
    local id="$1"
    [ -n "$id" ] ||  N=shodan M="Provide an alert ID" log:ret:1

    "___x_cmd_shodan_alert_info___${format}"
}

___x_cmd_shodan_alert_info___app(){
    local data; data="$( ___x_cmd_shodan_alert_info___raw )"   || shodan:data:ret
    ___x_cmd_pipevar data    ___x_cmd_shodan_alert_info___parse_json2csv | x csv static_tab
}


___x_cmd_shodan_alert_info___csv(){
    local data
    data="$( ___x_cmd_shodan_alert_info___raw )"    || shodan:data:ret
    ___x_cmd_pipevar data ___x_cmd_shodan_alert_info___parse_json2csv
}

___x_cmd_shodan_alert_info___tsv(){
    local data
    data="$( ___x_cmd_shodan_alert_info___raw )"    || shodan:data:ret
    ___x_cmd_pipevar data ___x_cmd_shodan_alert_info___parse_json2csv | x csv 2tsv
}

___x_cmd_shodan_alert_info___json(){
    local data
    data="$( ___x_cmd_shodan_alert_info___raw )"    || shodan:data:ret
    ___x_cmd_pipevar data
}


___x_cmd_shodan_alert_info___parse_json2csv(){
    x ja jl2c .name .id .filters.ip .created .has_triggers|\
        x csv awk '{ip_col = juq(cval(3)); gsub("\",\"", ",", ip_col); print cval(1)","cval(2)","ip_col","cval(4)","cval(5) }' |\
        x csv header --add Name ID IP Created Has_triggers
}

___x_cmd_shodan_alert_info___raw(){
    ___x_cmd_shodan_curl get "/shodan/alert/${id}/info"
}


