// Package premium declares the configuration template specs for premium
// (SHARED_POOL / LOGICAL_CLUSTER) clusters and wires them into a templategen
// Generator. Each spec's content (Base + Apply) lives in its own component file
// (premium_*.go) so it can be owned and edited by that component's dev in
// isolation.
//
// Convention (see templategen.Spec): Base holds the LATEST version's config;
// Apply adapts older / in-test versions down from it. When a new version becomes
// the latest, move its config into Base and add an Apply branch for the version
// it replaced — never grow Base with a stack of "new version adds X" branches.
package premium

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

// VersionFor returns a resolver (for templategen.Generator.GenerateAll) that
// maps each config type to the version it should be generated and bound at. Most
// components track the cluster's rollout version; components with an independent
// release line (e.g. tiproxy) override it here. As more components diverge onto
// their own version lines, add cases here — this is the single place that owns
// the premium per-component version policy.
func VersionFor(clusterVersion string) func(configType string) string {
	return func(configType string) string {
		switch configType {
		case pb.SHARED_POOL_CONFIG_TIPROXY:
			if clusterVersion == "v8.5.4" {
				return TiProxyVersion
			}
			return clusterVersion
		default:
			return clusterVersion
		}
	}
}

// Generator generates the premium base-data templates. This file only wires the
// per-config-type specs together; the order mirrors the original ctl migration
// so behaviour (and golden comparisons) stay stable.
var Generator = templategen.New([]templategen.Spec{
	specPD,
	specPDScheduling,
	specPDTSO,
	specResourceManager,
	specTiKV,
	specTiKVWorker,
	specCoprocessorWorker,
	specTiFlashWriteLearner,
	specTiFlashComputeLearner,
	specTiFlashCompute,
	specTiFlashWrite,
	specTiDBWorker,
	specTiDB,
	specDumpling,
	specTiProxy,
	specSEM,
	specSchemaManager,
	specBRAutoBackup,
	specBRRestore,
	specBRT2DFSGC,
	specBRT3Archive,
	specBRClassicRestore,
})
