# shellcheck shell=bash disable=SC2034,SC2154
# Section: add & update
# TODO: What parameters does config have
# https://gitea.com/api/swagger#/repository/repoCreateHook
___x_cmd_fjo_repo_hook_create() {
    param:scope     ___x_cmd_fjo
    param:dsl       <<A
options:
    --repo|-r               "<owner_path>/<repo_path>"                                              <>:RepoName
    --url                   "The URL to which the payloads will be delivered."                      <>
    --content_type          "The media type used to serialize the payloads."                        <>
    --type                  "type"                                                                  <>    = dingtalk discord gitea gogs msteams slack telegram feishu wechatwork packagist
    --events                "events the hook is triggered for.(array usage,interval)"               <>="push"
    --branch_filter         "branch filter"                                                         <>=""
    --authorization_header  "authorization header"                                                  <>=""
    --active                "Determines if notifications are sent when the webhook is triggered."
    --json|-j               "output json data"
A
    param:run

    local config
    config=$(x jo "{
        url:\"$url\",
        ${content_type+"content_type:$content_type"},
    }")
    events=$(x jo "[$events]")

    local gen_fjo_json
    gen_fjo_json="$(param:option2json -url -repo +config 'active=^^active')"

    ___x_cmd_fjo_param_init_owner_repo
    ___x_cmd_fjo_curl post "/repos/${owner_repo}/hooks" "gen_fjo_json" | ___x_cmd_fjo_hook____ui_handler Creating
}
