package consts

import "fmt"

const (
	AnnotationKeyEKSEndpoint   = "infra.pingcap.com/eks-endpoint"
	AnnotationKeyEKSName       = "network.cloud.pingcap.com/eks-name"
	AnnotationKeyDataplaneName = "network.cloud.pingcap.com/dataplane"

	// AnnotationKeyConfirmDeletion is used to confirm a CR should be deleted
	// Only CR with this annotation and value "true" will trigger the controller to delete the CR and its resources
	AnnotationKeyConfirmDeletion = "tidbcloud.com/confirm-deletion"
	// AnnotationKeyDeletionTrigger triggers the deletion
	// TODO: we should reuse confirm-deletion annotation
	AnnotationKeyDeletionTrigger = "pingcap.com/deletion-trigger"
	// AnnotationKeyBuiltinNodePool marks nodepools created by dataplane controller.
	AnnotationKeyBuiltinNodePool = "tidbcloud.com/builtin-nodepool"

	LastAppliedConfigAnnotation = "tidbcloud.com/last-applied-configuration"

	UseSelfManagedNodegroupAnnotation = "tidbcloud.com/use-self-managed-nodegroup"

	// ClusterFeatureUseSelfSignedCertForTiDBComponents indicates using self-signed certificates for inter-components mTLS communication
	ClusterFeatureUseSelfSignedCertForTiDBComponents = "self-signed-cert-for-tidb-components"

	// ClusterFeatureSelfSignedCertForTidbServer indicates using self-signed certificate for tidb server on SQL port
	// This feature should be used for development test only
	ClusterFeatureSelfSignedCertForTidbServer = "self-signed-cert-for-tidb-server"

	// ClusterFeatureUseAtRestEncryption is formal version of cluster-controller/controllers/cluster/task/common/tidbcluster.go:annoKeyEnableKMS
	ClusterFeatureUseAtRestEncryption = "at-rest-encryption" // see also https://docs.pingcap.com/tidb/stable/encryption-at-rest
	// ClusterFeatureNoScaleOutTiDBInParallel is used to disable to scale out tidb in parallel
	ClusterFeatureNoScaleOutTiDBInParallel = "no-scale-out-tidb-in-parallel"
	ClusterFeatureUseCMEK                  = "cmek"
	// ClusterFeatureDedicatedSG is used to decide whether to use dedicated security group for managing traffic filter(white-list)
	// for public LB. For AWS only.
	ClusterFeatureDedicatedSG            = "dedicated-sg"
	ClusterFeatureTiDBExposeOOMPath      = "tidb-expose-oom-path"
	ClusterFeatureTiDBExposeReplayerPath = "tidb-expose-replayer-path"

	// ClusterFeatureWildcardDNS indicates whether to use wildcard DNS for tidb-server
	ClusterFeatureWildcardDNS = "wildcard-dns"

	// ClusterFeatureDisableNodePoolDataPlaneLabel disable cluster-controller to set GKE nodepool's NodeConfig.Labels with
	// cloud.pingcap.com/node-group-type: "data-plane" because change it will cause existing nodes without this label restart.
	ClusterFeatureDisableNodePoolDataPlaneLabel = "disable-nodepool-data-plane-label"

	// ClusterFeature3LayerNodePool add taint and label to new nodepool in 3-layer
	// It's designed to avoid pods of migrated clusters being scheduled to 3-layer nodepool, which may break customers' authorization config of audit log
	// NOTE: it's only worked for gcp but will enabled for all clouds(for later deprecating process)
	ClusterFeature3LayerNodePool = "3-layer-node-pool"

	// ClusterFeatureTiProxyCertLayoutV1 is used for switch certificate layout from legacy to v1, which is required by
	// self-signed certificate feature.
	// Enable this feature for clusters without tiproxy has no impacts.
	ClusterFeatureTiProxyCertLayoutV1 = "tiproxy-cert-layout-v1"

	// ClusterFeatureSetPriorityClass is used to set priority class for all pods in the tidb cluster.
	// Since it needs to restart pods for existing clusters, let's only enable it for newly created clusters.
	ClusterFeatureSetPriorityClass = "set-priority-class"

	// ClusterFeatureUseTiDBOperatorV2 is used to enable TiDB Operator v2 to manage tidb clusters.
	ClusterFeatureUseTiDBOperatorV2 = "use-tidb-operator-v2"

	// ClusterFeatureUseVolumeAttributesClass is used to enable VAC to modify volumes in tidb operator v2.
	ClusterFeatureUseVolumeAttributesClass = "use-volume-attributes-class"

	// ClusterFeatureDisableScheduleTiProxyInTheSameZoneWithTiDB is used to disable scheduling tiproxy in the same zone with tidb.
	ClusterFeatureDisableScheduleTiProxyInTheSameZoneWithTiDB = "disable-schedule-tiproxy-in-the-same-zone-with-tidb"

	// ClusterFeatureDisableSyncTiDBSpecChangesForEnablingTiproxy is used to disable syncing TiDB spec changes to TiDB when TiProxy is enabled.
	ClusterFeatureDisableSyncTiDBSpecChangesForEnablingTiproxy = "disable-sync-tidb-spec-changes-for-enabling-tiproxy"

	// ClusterFeatureLegacyTiProxySettings is used for compatibility with the existing clusters.
	// For clusters with this feature enabled, the tiproxy will use the legacy settings:
	// 1. configure `graceful-wait-before-shutdown` to 15 seconds for tidb instead of 30 seconds
	// 2. create tiproxy pods WITHOUT readiness probe
	// 3. use dynamic calculated value for `terminationGracePeriodSeconds` of tiproxy pods instead of constant 20 minutes.
	ClusterFeatureLegacyTiProxySettings = "legacy-tiproxy-settings"

	// ClusterFeatureDisableV2PDReadinessProbe is used to disable readiness probe of pd in tidb operator v2
	ClusterFeatureDisableV2PDReadinessProbe = "disable-v2-pd-readiness-probe"

	// ClusterFeatureEnableGracefulShutdown is used to enable graceful shutdown for tidb clusters.
	// When it's enabled, will do a serials of optimizations to make sure the cluster can be gracefully shutdown.
	ClusterFeatureEnableGracefulShutdown = "enable-graceful-shutdown"

	// ClusterFeatureRemoveNEGAnnotation is used to remove the annotation "cloud.google.com/neg" for k8s services.
	ClusterFeatureRemoveNEGAnnotation = "remove-neg-annotation"

	// ClusterFeatureUsePDReadyAPIV2 is used to enable the PD ready API with tidb operator v2.
	ClusterFeatureUsePDReadyAPIV2 = "use-pd-ready-api-v2"

	AnnoValTrue = "true"

	// ClusterUpdateAnnotationKeyInstanceType indicates the cluster need to be updated as instance types changed.
	// the value should be a list of component names, separated by comma.
	ClusterUpdateAnnotationKeyInstanceType = "eks.infra.pingcap.com/cluster-update-instance-type"

	// CMEKEnabled indicates whether the cluster is using CMEK.
	CMEKEnabledKey = "eks.infra.pingcap.com/cmek-enabled"

	// KMSEnabledKey is the annotation key for whether the cluster enables kernel at reset encryption
	KMSEnabledKey = "tikv.cloud.pingcap.com/enable-kms"

	// This annotation is used for setting control plane's version.
	// New cluster will be created after EKS/GKE ClusterStatus.NodeVersion is set now.
	// But the NodeVersion can not be set for some existing clusters because it has been used
	// for some names and selectors.
	// It's only for compatibility now.
	AnnoKeyControlPlaneVersion = "cluster.cloud.pingcap.com/control-plane-version"

	// TcInstanceTypeAnnotationKey indicates the current instance type used in TidbCluster.
	TcInstanceTypeAnnotationKey = "infra.pingcap.com/instance-type"

	AnnoInstanceTypeSeparator = ","

	AnnSysctlInit    = "tidb.pingcap.com/sysctl-init"
	AnnSysctlInitVal = "true"

	DefaultLoadBalancerIDAnnotationKey = "tidbcloud.com/default-tidbgroup-access-id"

	O11yAgentReleaseNamespace       = "o11y.cloud.pingcap.com/release-namespace"
	O11yServiceDNSNameAnnotationKey = "o11y.cloud.pingcap.com/service-dns-name"
	O11yClusterStatusAnnotationKey  = "o11y.cloud.pingcap.com/status"
	// AnnotationKeyBYOCVPCPeeringID is added to KubernetesAgent CRs so ACS can pass
	// the dataplane-to-o11y VPC peering connection to o11y backend route setup.
	AnnotationKeyBYOCVPCPeeringID = "o11y.cloud.pingcap.com/byoc-vpc-peering-id"
	// AnnotationKeyBYOCDataplaneVPCCIDR is added to KubernetesAgent CRs so ACS can pass
	// the dataplane VPC CIDR to o11y backend route setup.
	AnnotationKeyBYOCDataplaneVPCCIDR = "o11y.cloud.pingcap.com/byoc-dataplane-vpc-cidr"
	// AnnotationKeyDataplaneNodeSpecs is a comma-separated, sorted list of Dedicated
	// worker node-spec values (e.g. "2C8G,4C8G,8C16G") on this dataplane. ACS uses it
	// to create per-spec vector DaemonSets that select nodes via the node-spec label.
	AnnotationKeyDataplaneNodeSpecs = "o11y.cloud.pingcap.com/dataplane-node-specs"
	// AnnotationKeyO11yVectorHostNetwork is the DPM-to-ACS control signal for
	// Vector host networking. ACS watches KubernetesAgent changes and, when this
	// annotation is exactly "true", overrides the final Vector Helm values with
	// podHostNetwork=true and dnsPolicy=ClusterFirstWithHostNet.
	AnnotationKeyO11yVectorHostNetwork = "o11y.cloud.pingcap.com/vector-host-network"
	// O11yIDAnnotationKey is added to a Network CR, represents s3/gcs id in o11y infra.
	O11yIDAnnotationKey = "o11y.cloud.pingcap.com/id"
	// MetricInterfaceEndpointNameAnnotationKey is added to a Cluster CR.
	MetricInterfaceEndpointNameAnnotationKey = "o11y.cloud.pingcap.com/metric-interface-endpoint-name"
	S3GatewayEndpointNameAnnotationKey       = "o11y.cloud.pingcap.com/s3-gateway-endpoint-name"
	// MetricsO11yIDAnnotationKey represents prometheus id in o11y infra.
	MetricsO11yIDAnnotationKey = "o11y.cloud.pingcap.com/metrics-id"

	// AnnoKeyTiProxyToggleWorkflow records the currently running tiproxy toggle workflow.
	// This annotation will be automatically deleted once this workflow is finished.
	// If a cluster is annotated with this annotation, the cluster-server will return `clusterPhase: SYNCING`
	// even if `cluster.FullSynced() == true`.
	AnnoKeyTiProxyToggleWorkflow = "tidbcloud.com/tiproxy-toggle-workflow"
	// AnnoKeyWaitTimeForToggleLBTarget represents the wait time for toggle lb target.
	// The default value is 300s.
	AnnoKeyWaitTimeForToggleLBTarget = "tidbcloud.com/wait-time-for-toggle-lb-target"
	// AnnoKeyLBTargetOnTiProxyPrefix indicates whether the LB target is on TiProxy.
	// the group id will be appended to form the annotation key.
	AnnoKeyLBTargetOnTiProxyPrefix = "flag.tidbcloud.com/lb-target-on-tiproxy"

	// AnnotationKeyLastSyncedCloudTags stores the last successfully synced cloud tags in JSON format
	// Used by resource tagger controller to avoid unnecessary API calls when tags have not changed.
	AnnotationKeyLastSyncedCloudTags = "tidbcloud.com/last-synced-cloud-tags"
	// AnnotationKeyCloudTagsReconcileTrigger stores the inherited dataplane cloud tag snapshot that last triggered reconcile.
	AnnotationKeyCloudTagsReconcileTrigger = "tidbcloud.com/cloud-tags-reconcile-trigger"

	// AnnotationKeyPublicDNSReachable records the latest public DNS reachability probe result for public LoadBalancer CRs.
	AnnotationKeyPublicDNSReachable = "tidbcloud.com/public-dns-reachable"
	// AnnotationKeyPublicDNSReason records the latest public DNS reachability probe reason.
	AnnotationKeyPublicDNSReason = "tidbcloud.com/public-dns-reason"
)

const (
	// AnnoValueBugNameCMEKNotEnabled indicates this cluster want to enable CMEK but actually not,
	// refer to https://pingcap.feishu.cn/wiki/VyYswDSTgiTe3rkBkAdcNtlWnte
	AnnoValueBugNameCMEKNotEnabled = "cmek-not-enabled"
)

const (
	// AnnotationKeyACKAddonRecoveryAttemptPrefix tracks the number of recovery attempts
	// for an ACK addon that failed due to cluster updating state. The full annotation key
	// includes the addon name, e.g: "cloud.pingcap.com/ack-addon-recovery-attempt-ack-goatscaler"
	AnnotationKeyACKAddonRecoveryAttemptPrefix = "cloud.pingcap.com/ack-addon-recovery-attempt-"

	// AnnotationKeyACKAddonRecoveryTimestampPrefix tracks the timestamp of the last recovery
	// attempt for an ACK addon. Used to calculate exponential backoff. The full annotation key
	// includes the addon name, e.g: "cloud.pingcap.com/ack-addon-recovery-timestamp-ack-goatscaler"
	AnnotationKeyACKAddonRecoveryTimestampPrefix = "cloud.pingcap.com/ack-addon-recovery-timestamp-"
)

func AnnoKeyLBTargetOnTiProxy(groupID string) string {
	return fmt.Sprintf("%s-%s", AnnoKeyLBTargetOnTiProxyPrefix, groupID)
}

func AnnoKeyACKAddonRecoveryAttempt(addonName string) string {
	return AnnotationKeyACKAddonRecoveryAttemptPrefix + addonName
}

func AnnoKeyACKAddonRecoveryTimestamp(addonName string) string {
	return AnnotationKeyACKAddonRecoveryTimestampPrefix + addonName
}
