package config

// DefaultNewArchInstanceTypes is the catalog the picker falls back to
// when cdc.newArch.instanceTypes is empty. Intentionally short — just
// a single 16c machine. With cpuPerRcu=1 this means every shard,
// regardless of rcu load, materializes as some replica count of 16c
// pods. Operators with mixed-rcu workloads should override this with
// a multi-tier catalog in the env config.
var DefaultNewArchInstanceTypes = []CDCNewArchInstanceType{
	{
		Name:          "16c",
		CpuPerReplica: 16,
		MemoryGi:      64,
		StorageGi:     200,
		Iops:          12000,
		ThroughputMbs: 1000,
	},
}

// DefaultNewArchRcuTiers is the user-facing rcu ladder the
// ListChangefeedSpecifications API falls back to when
// cdc.newArch.rcuTiers is empty. UI uses these to let a customer
// pick an rcu number; the rpsLimit on each tier is what the UI
// surfaces as "max RPS at this tier".
var DefaultNewArchRcuTiers = []CDCNewArchRcuTier{
	{RCU: 2, RPSLimit: 5000},
	{RCU: 4, RPSLimit: 10000},
	{RCU: 8, RPSLimit: 20000},
	{RCU: 16, RPSLimit: 40000},
	{RCU: 32, RPSLimit: 80000},
	{RCU: 64, RPSLimit: 160000},
	{RCU: 128, RPSLimit: 320000},
	{RCU: 256, RPSLimit: 640000},
}

var DefaultNewArchNodeSelector = map[string]string{
	"serverless.tidbcloud.com/node":          "adhoc",
	"adhoc-cpu":                              "16",
	"adhoc-memory":                           "64",
	"serverless.tidbcloud.com/capacity-type": "ON_DEMAND",
}

var DefaultNewArchTolerations = []NewArchToleration{
	{
		Key:      "serverless.tidbcloud.com/node",
		Operator: "Equal",
		Value:    "adhoc",
		Effect:   "NoSchedule",
	},
}

// NewArchInstanceTypes returns the catalog of cdc machine shapes the
// picker is allowed to choose from, falling back to the in-code
// default when nothing is configured. Returned slice is not copied;
// treat it as read-only.
func NewArchInstanceTypes() []CDCNewArchInstanceType {
	cfg := Global().CDCConfig.NewArch
	if len(cfg.InstanceTypes) > 0 {
		return cfg.InstanceTypes
	}
	return DefaultNewArchInstanceTypes
}

// NewArchRcuTiers returns the user-facing rcu ladder, falling back
// to the in-code default when the config file leaves rcuTiers empty.
// Returned slice is not copied; treat it as read-only.
func NewArchRcuTiers() []CDCNewArchRcuTier {
	cfg := Global().CDCConfig.NewArch
	if len(cfg.RcuTiers) > 0 {
		return cfg.RcuTiers
	}
	return DefaultNewArchRcuTiers
}

// NewArchCpuPerRcu returns the configured cpu-per-rcu conversion
// factor, defaulting to 1 when unset (or zero).
func NewArchCpuPerRcu() uint32 {
	cfg := Global().CDCConfig.NewArch
	if cfg.CpuPerRcu == 0 {
		return 1
	}
	return cfg.CpuPerRcu
}
