# shellcheck shell=bash disable=SC2034,SC2154
# shellcheck disable=SC2039,3043

xrc:mod:lib     fjo     team/ls             \
                        team/info           \
                        team/create         \
                        team/edit           \
                        team/rm             \
                        team/repo/_index    \
                        team/member/_index

___x_cmd_fjo_team(){
    param:subcmd ___x_cmd_fjo_team                  \
        ls              "list user or org team"     \
        info            "Get team info by id"       \
        create          "To create a team"          \
        "edit|ed"       "To edit a team"            \
        repo            "manage org team repo"      \
        member          "manage org team member"    \
        rm              "To delete a team"

    param:subcmd:try
    param:run


    ___x_cmd_fjo_team _param_help_doc
    return 1
}


# Section: org team utils
___x_cmd_fjo_team____ui_handler(){
    if  [ -n "$ENFORCE_JSON" ] || [ -n "$json" ]; then
        ___x_cmd_cmds_cat
        ___x_cmd_fjo_http_error
        return
    fi
    (
        local msg=
        local error_msg=
        case "$1" in
            Info)
                msg="get team info  success"
                error_msg="get team info fail."
                ;;
            Creating|Update)
                msg="$1 org team $name success"
                error_msg="$1 org team failure: $name."
                ;;
        esac
        ___x_cmd jo env . id=.id url=.url name=.name fjo_resp_err=.message owner=.organization.login
        if [ -n "$id" ]; then
            ___x_cmd_ui_tf true "$msg" ${id+"Id: $id"} ${name+"Name: $name"} ${owner+"Owner: $owner"} ${url+"Url: $url"}
        else
            ___x_cmd_ui_tf false "$error_msg"
            ___x_cmd_fjo____handle_resp
            return 1
        fi
    )
}
