# shellcheck shell=bash disable=SC2154,2034
___x_cmd_shodan_notifier_ls(){
    local X_help_cmd='x help -m shodan notifier ls';   help:arg:parse
    shodan:arg:format:all
    shodan:info "Get a list of all the notifiers that the user has created"

    "___x_cmd_shodan_notifier_ls___${format}"
}

___x_cmd_shodan_notifier_ls___app(){
    local data
    data=$(___x_cmd_shodan_notifier_ls___csv | x csv --app --return print) || shodan:data:ret

    [ -n "$data" ] || return

    local notifier_id=${data%%,*}

    local id=3
    x ui select id "Next move for notifer id=${notifier_id}"  \
        "info"      \
        "remove"    \
        "Abort"

    case "$id" in
        1)  ___x_cmd_shodan_notifier_info       "$notifier_id" ;;
        2)  ___x_cmd_shodan_notifier_rm         "$notifier_id" ;;
        3)  return 0 ;;
    esac
}

___x_cmd_shodan_notifier_ls___csv(){
    local data; data=$( ___x_cmd_shodan_notifier_ls___raw )      || shodan:data:ret
    ___x_cmd_pipevar data ___x_cmd_shodan_notifier_ls___parse_json2csv
}

___x_cmd_shodan_notifier_ls___tsv(){
    local data; data=$( ___x_cmd_shodan_notifier_ls___csv )      || shodan:data:ret
    ___x_cmd_pipevar data
}

___x_cmd_shodan_notifier_ls___json(){
    local data; data="$( ___x_cmd_shodan_notifier_ls___raw )"    || shodan:data:ret
    ___x_cmd_pipevar data
}


___x_cmd_shodan_notifier_ls___raw(){
    X_CCMD_TIMEOUT=5s ___x_cmd_shodan_curl get "/notifier"
}

___x_cmd_shodan_notifier_ls___parse_json2csv(){
    x jo .matches.\* |\
        x ja jl2c  .id .provider .description .args.to |\
        x csv header --add  ID  Provider Description Args_to
}
