package window_function

import (
	"fmt"
	"strings"
)

const (
	// host name 是对应 testbed 里 workload 的 $name-peer，比如 testbed 里有个 name: tidb 的节点，那 host name 就是 tidb-peer
	tiupTopoTpl = `
# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
  arch: %s
  user: "tidb"
  ssh_port: 22
  deploy_dir: "/tiup/deploy"
  data_dir: "/tiup/data"
  enable_tls: %s
server_configs:
  pd: {}
  tidb: {}
  tikv: {}
  tiflash: 
    logger.level: debug
  tiflash-learner: {}
pd_servers:
  - host: pd-peer
%s
monitoring_servers:
  - host: tiup-peer
grafana_servers:
  - host: tiup-peer
alertmanager_servers:
  - host: tiup-peer
`
	productionMirror = "https://tiup-mirrors.pingcap.com"
	stagingMirror    = "http://staging.tiup-server.pingcap.net"
	//productionMirror = "http://172.16.5.134:8987"
	//stagingMirror    = "http://172.16.5.139:8988"
	clusterName = "debug"
)

func renderTopo(tidbs int, tikvs int, tiflashs int) string {
	tidbPrefix := "tidb_servers:"
	tikvPrefix := "tikv_servers:"
	tiflashPrefix := "tiflash_servers:"

	topoList := []string{}
	if tidbs > 0 {
		tidbTpl :=
			`  - host: tidb-%d-peer`
		tidbList := []string{tidbPrefix}
		for i := 1; i <= tidbs; i++ {
			tidbList = append(tidbList, fmt.Sprintf(tidbTpl, i))
		}
		topoList = append(topoList, strings.Join(tidbList, "\n"))
	}
	if tikvs > 0 {
		tikvTpl :=
			`  - host: tikv-%d-peer`
		tikvList := []string{tikvPrefix}
		for i := 1; i <= tikvs; i++ {
			tikvList = append(tikvList, fmt.Sprintf(tikvTpl, i))
		}
		topoList = append(topoList, strings.Join(tikvList, "\n"))
	}
	if tiflashs > 0 {
		tiflashTpl :=
			`  - host: tiflash-%d-peer`
		tiflashList := []string{tiflashPrefix}
		for i := 1; i <= tiflashs; i++ {
			tiflashList = append(tiflashList, fmt.Sprintf(tiflashTpl, i))
		}
		topoList = append(topoList, strings.Join(tiflashList, "\n"))
	}
	return strings.Join(topoList, "\n")
}
