package premium

import (
	pb "github.com/tidbcloud/config-center/proto/config_center"
	"github.com/tidbcloud/config-center/templategen"
)

var specTiDBWorker = templategen.Spec{
	ConfigType: pb.SHARED_POOL_CONFIG_TIDB_WORKER,
	Name:       "system template of premium tidb worker",
	Base: templategen.MustTOML(`
disaggregated-tiflash = true
tmp-storage-path = "/tmp/tidb_tmp"
tmp-storage-quota = 21474836480

[instance]
tidb_service_scope = "dxf_service"

[log]

[log.file]
max-backups = 3

[security]
enable-sem = true

[status]
record-db-label = true

[tikv-client]

[tikv-client.copr-cache]
capacity-mb = 0.0
max-server-connections = 2000`),
}

// specTiDB is the tidb resource-pool template. One template drives the default
// for both SHARED_POOL and LOGICAL_CLUSTER, so its bindings are explicit.
var specTiDB = templategen.Spec{
	ConfigType: pb.SHARED_POOL_CONFIG_TIDB,
	Name:       "system template of premium tidb resource pool",
	Bindings: []templategen.Binding{
		{ClusterType: pb.ClusterType_SHARED_POOL, ConfigType: pb.SHARED_POOL_CONFIG_TIDB},
		{ClusterType: pb.ClusterType_LOGICAL_CLUSTER, ConfigType: pb.LOGICAL_CLUSTER_CONFIG_TIDB},
	},
	Base: templategen.MustTOML(`
disaggregated-tiflash = true
graceful-wait-before-shutdown=180
tmp-storage-path = "/tmp/tidb_tmp"
tmp-storage-quota = 21474836480

[log]

[log.file]
max-backups = 3

[security]
enable-sem = true

[status]
record-db-label = true

[tikv-client]

[tikv-client.copr-cache]
capacity-mb = 0.0

[proxy-protocol]
fallbackable = true
networks = "*"
`),
	Apply: func(version string, data map[string]*pb.ParamItem) {
		if !IsV263(version) {
			return
		}
		data["instance.tidb_stmt_summary_enable_persistent"] = templategen.MustParam(true)
		data["instance.tidb_stmt_summary_filename"] = templategen.MustParam("/var/log/auditlog/tidb-statements.log")
	},
}
