# shellcheck shell=dash disable=SC2034,SC2154
# https://gitea.com/api/swagger#/organization/createOrgRepo
___x_cmd_fjo_org_repo_create() {
    param:scope     ___x_cmd_fjo
    param:dsl       '
type:
    access  =   private public
option:
    --org                "organization create repo"                                                         <>=""
    #1                   "repo names"
    --access             "private,public"                                                                   <>:access=private
    --readme             "Readme of the repository to create"                                               <>=""
    --license            "License to use"                                                                   <>=""
    --description        "Description of the repository to create"                                          <>=""
    --gitignores         "Gitignores to use"                                                                <>=""
    --issue_labels       "Label-Set to use"                                                                 <>=""
    --trust_model        "TrustModel of the repository"                                                     <>=""      = default collaborator committer collaboratorcommitter
    --default_branch     "DefaultBranch of the repository (used when initializes and in template)"          <>=""
    --template           "Whether the repository is template"
    --auto_init          "Whether the repository should be auto-initialized"
    --json|-j            "output json data"
'
    param:run

    local private=true
    [ "$access" = "public" ] && private=false

    local name=""
    [ -n "$org" ] || {
        for name in "$@"; do
            case "$name" in
                */*)    ;;
                *)      gjo:error "Please provide --org or add organization prefix before reponame"
                        return 1 ;;
            esac
        done
    }
    name="${___X_CMD_TX}"
    local gen_fjo_json
    gen_fjo_json="$(param:option2json -access +private +name 'template=^^template' 'auto_init=^^auto_init' )"

    for name in "$@"; do
        local this_org="${name%%/*}"
        [ "$this_org" != "$name" ] || this_org="$org"
        fjo:debug "$(x tmpl "$gen_fjo_json"  "${name##*/}")"
        ___x_cmd tmpl "$gen_fjo_json"  "${name##*/}"  | \
        ___x_cmd_fjo_curl post "/orgs/$this_org/repos" "@-" | ___x_cmd_fjo_repo____ui_handler Creating
    done
}