# shellcheck shell=dash

xrc:mod:lib gh     repo/release/attachment/ls        \
                    repo/release/attachment/info      \
                    repo/release/attachment/upload    \
                    repo/release/attachment/edit      \
                    repo/release/attachment/rm        \
                    repo/release/attachment/download  \
                    repo/release/attachment/downloadp

___x_cmd_gh_repo_release_attachment(){
    param:scope  ___x_cmd_github
    param:subcmd ___x_cmd_gh_repo_release_attachment                        \
        ls              "List repo release attachment"                      \
        info            "Get repo release attachment information"           \
        upload          "Upload repo release attachment"                    \
        "edit|ed"       "Edit repo release attachment information"          \
        rm              "Remove repo release attachment"                    \
        download        "download private repo release single attachment"   \
        downloadall     "download private repo release all attachment"      \
        downloadp       "download public repo release single attachment"    \
        downloadallp    "download public repo release all attachment"

    param:subcmd:try
    param:run

    ___x_cmd_gh_repo_release_attachment _param_help_doc
    return 1
}

# Section: attachment UI
___x_cmd_gh_release_attachment_____ui_handler(){
    if [ -n "$ENFORCE_JSON" ] || [ -n "$json" ]; then
        ___x_cmd_cmds_cat
        ___x_cmd_gh_http_error
        return
    fi
    (
        case "$1" in
            Upload|Edit)
                _inf_msg="$1 repo release attachment successfully"
                _err_msg="$1 repo release attachment failure"
                ;;
            Info)
                _inf_msg="Get repo release attachment info successfully"
                _err_msg="Get repo release attachment info failure"
                ;;
        esac

        local _id=""
        x jo env . _id=.id name=.name label=.label state=.state size=.size down_count=.download_count created_at=.created_at updated_at=.updated_at \
            down_url=.browser_download_url gh_resp_msg=.message gh_resp_err=.errors
        if [ -n "$_id" ]; then
            ___x_cmd_ui_tf  true "${_inf_msg}:" "Release_Attachment_Id: $_id" ${name:+"Name: $name"} ${label:+"Label: $label"}             \
                ${state:+"State: $state"} ${size:+"Size: $size"} ${down_count:+"Download_Count: $down_count"} ${down_url:+"Download_URL: $down_url"}   \
                ${created_at:+"Created_At: $created_at"} ${updated_at:+"Updated_At: $updated_at"}
        else
            ___x_cmd_ui_tf false "${_err_msg}:" >&2
            ___x_cmd_gh____handle_resp
            return 1
        fi
    )
}
# EndSection

