# shellcheck shell=dash disable=SC2034,SC2154 disable=SC2154
# https://codeberg.org/api/swagger#/repository/createCurrentUserRepo
___x_cmd_fjo_repo_create() {
    param:scope     ___x_cmd_fjo
    param:dsl       '
type:
    access  =   private public
option:
    #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     "Default Branch 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=""
    for name in "$@"; do
        local owner_type=user
        local org="${name%%/*}"
        [ "${name%%/*}" = "$name" ] || {
            if ! owner_type="$(___x_cmd_fjo_owner_type_query "${name%%/*}")"; then
                fjo:error "No found any onwer type. Please check ${name%%/*} owner exist"
                return 1
            fi
            name="${name##*/}"
        }
        [ "$owner_type" != "user" ] || unset org

        "___x_cmd_fjo_${owner_type}_repo_create" --access "${access}" ${readme:+"--readme"} ${readme:+"$readme"} \
            ${license:+"--license"} ${license:+"$license"} ${description:+"--description"} ${description:+"$description"} \
            ${gitignores:+"--gitignores"} ${gitignores:+"$gitignores"} ${issue_labels:+"--issue_labels"} ${issue_labels:+"$issue_labels"} \
            ${trust_model:+"--trust_model"} ${trust_model:+"$trust_model"} ${default_branch:+"--default_branch"} ${default_branch:+"$default_branch"} \
            ${template:+"--template"} ${auto_init:+"--auto_init"} ${org:+"--org"} ${org:+"$org"} "${name}"
    done
}
