package gkemindomains

import (
	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
	"github.com/tidbcloud/infra-provider/pkg/consts"
)

// UpgradeDecision selects the scheduling contract for one TiDB-node upgrade
// step. It is independent of the UpgradeOperation lifecycle phase.
type UpgradeDecision string

const (
	// UpgradeDecisionOption is internal state owned by the control plane. It must
	// not be accepted from UpgradeNodesRequest.
	UpgradeDecisionOption = "internal-gke-v1-min-domains-upgrade-decision"

	UpgradeDecisionMinDomains        UpgradeDecision = "min-domains"
	UpgradeDecisionWithoutMinDomains UpgradeDecision = "legacy"
)

// Applicable reports whether this is a three-zone GKE v1 cluster.
func Applicable(cluster *cloudv1.Cluster) bool {
	return cluster != nil &&
		cluster.GetProviderType() == cloudv1.ProviderTypeGKE &&
		cluster.FeatureEnabled(consts.ClusterFeatureGCP3LayerNodePool) &&
		!cluster.FeatureEnabled(consts.ClusterFeatureUseTiDBOperatorV2) &&
		cluster.Spec.Kubernetes.Cloud.GCP != nil &&
		len(cluster.Spec.Kubernetes.Cloud.GCP.NodeZones) == RequiredZoneCount
}
