# shellcheck shell=bash disable=SC2034,SC2154 disable=SC2154
___x_cmd_fjo_repo_branch_protection_set(){
    param:dsl       '
options:
    --repo|-r                                "repo name"                     <>:RepoName
    --branch_name                            "branch name"                  <>
    --approvals_whitelist_teams              "approvals whitelist teams"    <>=""
    --merge_whitelist_teams                  "merge whitelist teams"        <>=""
    --merge_whitelist_usernames              "merge whitelist usernames"    <>=""
    --protected_file_patterns                "protected file patterns"      <>=""
    --push_whitelist_teams                   "push whitelist teams"         <>=""
    --push_whitelist_usernames               "push whitelist usernames"     <>=""
    --required_approvals                     "required approvals"           <>:Number=""
    --status_check_contexts                  "status check contexts"        <>=""
    --unprotected_file_patterns              "unprotected file patterns"    <>=""
    --enable_push                            "enable push"
    --enable_push_whitelist                  "enable push whitelist"
    --enable_approvals_whitelist             "enable approvals whitelist"
    --require_signed_commits                 "require signed commits"
    --block_on_outdated_branch               "block on outdated branch"
    --block_on_rejected_reviews              "block on rejected reviews"
    --dismiss_stale_approvals                "dismiss stale approvals"
    --push_whitelist_deploy_keys             "push whitelist deploy keys"
    --approvals_whitelist_username           "approvals whitelist username"
    --block_on_official_review_requests      "block on official review requests"
    --json|-j                                "output json data"
'
    param:run

    local gen_fjo_json
    gen_fjo_json="$(param:option2json -repo)"

    fjo:debug "data:$gen_fjo_json"
    ___x_cmd_fjo_param_init_owner_repo
    ___x_cmd_fjo_curl post "/repos/${owner_repo}/branch_protections" "gen_fjo_json" | (
        if [ -n "$ENFORCE_JSON" ] || [ -n "$json" ]; then
            ___x_cmd_cmds_cat
            ___x_cmd_fjo_http_error
            return
        fi

        x jo env . name=.branch_name fjo_resp_err=.message
        if [ -n "$name" ]; then
            ___x_cmd_ui_tf true "set protection branch $1 success"
        else
            ___x_cmd_ui_tf false "set protection branch $1 failed."
            ___x_cmd_fjo____handle_resp
            return 1
        fi
    )
}
