# shellcheck shell=dash

___x_cmd_hub_file_ll(){
    ___x_cmd_hub_file_ls -l "$@"
}

___x_cmd_hub_file_ls(){
    local X_help_cmd='___x_cmd_hub___help file ls'
    help:arg:parse
    local json; local recurse; local long
    while [ $# -gt 0 ] ; do
        case "$1" in
            --json|-j)      json=true;      shift ;;
            --recurse|-R)   recurse=true;   shift ;;
            --long|-l)      long=detail;    shift ;;
            *)              break ;;
        esac
    done

    local remotefp="$1"
    remotefp="$(___x_cmd_hub_file_normalize_remotefp "$remotefp")"

    # TODO: use x curl new way to handle error
    local resp=
    resp="$(___x_cmd_hub_u_curl get "/api/v0/file?res=$(___x_cmd url encode "$remotefp")&type=${long}&recurse=${recurse}")" || {
        ___x_cmd_hub_u_handle_resp false "Failed to ls file:"
        return 1
    }

    [ -z "$json" ] || { printf "%s\n" "$resp"; return 0; }
    if [ -n "$long" ] ; then
        printf "%s" "$resp" | \
            ___x_cmd jo 2c                .path  .is_public .user_list .is_dir .size  .created_at | \
            ___x_cmd csv header --add     path   is_public user_list is_dir size  created_at  | \
            ___x_cmd_hub_u_st_tab  30%,10,-,10,10,-
    else
        local code=; code="$(xrc cat awk/lib/core.awk awk/lib/j/json.awk awk/lib/j/jiter.awk )"
        printf "%s" "$resp" | ___x_cmd_cmds awk "$code"'
            { jiget_after_tokenize_unquote($0, ".") }'
    fi
}

___x_cmd_hub_file_ls___app(){
    :
}

___x_cmd_hub_file_ls___csv(){
    :
}

___x_cmd_hub_file_ls___json(){
    :
}

___x_cmd_hub_file_ls___raw(){
    :
}

# Section: parser
___x_cmd_hub_file_ls___parse_json2csv(){
    :
}
# EndSection
