# shellcheck shell=dash disable=SC2154,SC2034
# https://gitea.com/api/swagger#/repository/repoEdit
___x_cmd_fjo_repo_edit(){
    param:scope     ___x_cmd_fjo
    param:dsl       '
type:
    Access  =   private public
option:
    #1                   "<owner_path>/<repo_path>"                                                                         <>:RepoName
    --name               "repo alias"                                                                                       <>=""
    --access             "private,public"                                                                                   <>=:Access=""
    --website            "a URL with more information about the repository"                                                 <>=""
    --description        "Description of the repository to create"                                                          <>=""
    --projects_mode      "repo to only allow repo-level projects, owner to only allow owner projects, all to allow both"    <>=""
    --default_branch     "DefaultBranch of the repository (used when initializes and in template)"                          <>=""
    --template           "Whether the repository is template"
    --has_releases       "Whether to allow release."

    --yes|-y             "Ignore access private prompt interception"
    --json|-j            "output json data"
'
    param:run
    local repo="$1"
    ___x_cmd_fjo_param_init_owner_repo

    local private=""
    case "$access" in
        private)
            private=true
            [ "$yes" = "true" ] || ___x_cmd_ui_yesno "Are you sure to edit $1 repository access to $(___x_cmd_ui bold red "$access") ?${___X_CMD_UNSEENCHAR_NEWLINE}  - Will only authorized users will have access${___X_CMD_UNSEENCHAR_NEWLINE}  - Will loss of all stars and watchers${___X_CMD_UNSEENCHAR_NEWLINE}" || return 1
            ;;
        public)         private=false           ;;
    esac


    local gen_fjo_json=
    gen_fjo_json="$( param:option2json -repo -access -json "${private:+"+private"}" 'template=^^template' 'has_releases=^^has_releases' )"

    fjo:debug  "$gen_fjo_json"
    printf "%s" "${gen_fjo_json}" | ___x_cmd_fjo_curl patch "/repos/${owner_repo}" "@-" | ___x_cmd_fjo_repo____ui_handler Edit

}
