# shellcheck shell=dash disable=SC3043,SC2154
# https://docs.github.com/en/rest/releases/assets#upload-a-release-asset
# TODO: !!!Request URL query encode
___x_cmd_gh_repo_release_attachment_upload() {
    param:scope     ___x_cmd_github
    param:dsl    '
options:
    #1              "target upload attachment file path"                            <>
    --repo|-r       "<owner_path>/<repo_path>"                                      <>:RepoName
    --release_id    "Release ID"                                                    <>:Number
    --name          "The file name of the attachment(URL-encode)(default filename)" <>=""
    --label         "An alternate short description of the attachment(URL-encode)"  <>=""
    --file_type     "Target upload attachment media type"                           <>="octet-stream"
    --endpoint      "upload endpoint"                                               <>="https://uploads.github.com"
    --json|-j       "output json data"
'
    param:run
    [ -n "$1" ] || M='accepts 1 arg (target upload attachment file path), received empty' arg:ret:64
    local _file_path="$1"
    [ "$_file_path" != '-' ] || _file_path="$(___x_cmd_cmds_cat)"
    [ -n "$name" ] || name="${_file_path##*/}"

    local ___X_CMD_API_GH_ENDPOINT="$endpoint"
    ___x_cmd_gh_param_init_owner_repo
    ___x_cmd_gh_curl upload "/repos/${owner_repo}/releases/${release_id##*/}/assets?name=${name}${label:+"&&label=$label"}" "$_file_path" | \
        ___x_cmd_gh_release_attachment_____ui_handler Upload
}
