# shellcheck shell=dash

___x_cmd_scoop___xmirror(){
    [ $# -gt 0 ]    ||  set - --help
    local op="$1";      shift
    case "$op" in
        ls|set|unset|current)
                        ___x_cmd_scoop___xmirror_"$op" "$@" ;;  # In the future, we will put the mirror code here ...

        -h|--help)      ___x_cmd help -m scoop mirror       ;;
        *)              ___x_cmd help -m scoop mirror >&2; return 64 ;;
    esac
}

___x_cmd_scoop___xmirror_set(){
    [ $# -gt 0 ]    ||  set - gitee
    local name="$1"

    case "$name" in
        gitee)
            scoop:info --Thanks "https://gitee.com/scoop-installer/scoop" "适合中国大陆用户使用的 scoop 镜像优化库"
            ___x_cmd_scoop___xmirror_unset___inner || return $?
            ___x_cmd_scoop___bin config SCOOP_REPO "https://gitee.com/scoop-installer/scoop" || return $?
            ___x_cmd_scoop___bin config scoop_branch develop || return $?
            ___x_cmd_scoop___bin update || return $?
            ;;
        -h|--help)
            ___x_cmd help -m scoop mirror set ;;
        *)
            N=scoop M="Only support gitee now" log:ret:64
            ;;
    esac
}

___x_cmd_scoop___xmirror_unset(){
    ___x_cmd_scoop___xmirror_unset___inner || return $?
    scoop:info "Unset mirror successfully"
}

___x_cmd_scoop___xmirror_unset___inner(){
    scoop:info "Unset mirror"
    ___x_cmd_scoop___bin config SCOOP_REPO "https://github.com/ScoopInstaller/Scoop"
    # ___x_cmd_scoop___bin config rm mirror
}

___x_cmd_scoop___xmirror_ls(){
    printf "%s\n" \
        "Code       Url                                         Name"                    \
        "gitee      https://gitee.com/scoop-installer/scoop     Mirror repositories hosted on Gitee"
}

___x_cmd_scoop___xmirror_current(){
    ___x_cmd_scoop___bin bucket list
}
