package consts

import "time"

const (
	ProviderTypeAWS  = "aws"  // gardener-aws provider
	ProviderTypeGCP  = "gcp"  // gardener-gcp provider
	ProviderTypeEKS  = "eks"  // cloud-native and 3layer arch provider
	ProviderTypeGKE  = "gke"  // cloud-native and 3layer arch provider
	ProviderTypeAKS  = "aks"  // azure 3layer arch provider
	ProviderTypeKinD = "kind" // KinD (Kubernetes in Docker) provider
	ProviderTypeACK  = "ack"  // aliyun 3layer arch provider

	ProviderTypeAWSFreeTier   = "aws-free-tier"
	ProviderTypeAWSSharedTier = "aws-shared-tier"
	ProviderTypeGCPSharedTier = "gcp-shared-tier"

	AMD64ArchName = "amd64"
	ARM64ArchName = "arm64"

	TiDBCloudPrefix              = "tidbcloud-"
	ClusterPrefix                = "db"
	SharedBucketPrefixDBAuditLog = "audit_log"

	DefaultMaxConcurrentReconciles = 1

	// BRGCPSecretName is the secret name used to store GCP Application Default Credentials for Backup and Restore.
	BRGCPSecretName    string = "gcp-br-credentials" // #nosec G101
	BRGCPSecretDataKey string = "credentials"

	// BootstrapSQLCMKey is the key name of bootstrap sql configmap
	BootstrapSQLCMKey = "bootstrap-sql"

	// LocalOperatorNamespace is the namespace in which the tidb-operator will be installed.
	LocalOperatorNamespace = "tidb-admin"

	CertManagerGroup                  = "awspca.cert-manager.io"
	CertificateDuration               = 10 * 365 * 24 * time.Hour // 10 years
	SelfSignedComponentCACertDuration = 15 * 365 * 24 * time.Hour // 15 years
	SelfSignedComponentCertDuration   = 13 * 30 * 24 * time.Hour  // 13 months
	RenewBefore                       = 30 * 24 * time.Hour       // 30 days
	CertOrganization                  = "PingCAP"

	Gi = 1024 * 1024 * 1024

	ServiceName                     = "infra-provider"
	LightstepEndpoint               = "ingest.lightstep.com:443"
	RegionalClusterServiceNamespace = "cluster-service"
	DataplaneAdminNamespace         = "tidb-admin"

	// the name of readonly cluster-controller
	ReadonlyClusterController = "readonly-cluster-controller"

	// ClusterRoleViewerName is the name of ClusterRole which has readonly permissions in k8s
	ClusterRoleViewerName = "cluster-viewer"

	// DefaultWaitTimeForToggleLBTarget is the default wait time for toggle lb target between TiProxy and TiDB.
	// You can override it by setting the annotation `AnnoKeyWaitTimeForToggleLBTarget` on the cluster.
	DefaultWaitTimeForToggleLBTarget = "300s"

	// ServerLabelKeyGroup is a Server Label key that represents which TiDB Node Group this server belongs to.
	ServerLabelKeyGroup = "group"
	// TODO(ideascf): add it to preconfig keys. As this configuration should be synced to all existing clusters,
	//   we can't add it to preconfig keys now.
	// tiproxyBalanceLabelConfKey is the configuration key of the label name for the tiproxy balance.
	// Currently, we hard-code the conf value to `ServerLabelKeyGroup`.
	// Refer to https://docs.pingcap.com/tidb/stable/tiproxy-load-balance/#label-based-load-balancing.
	TiProxyBalanceLabelConfKey = "balance.label-name"

	// DefaultTidbGracefulShutdownWaitSeconds is the default `graceful-wait-before-shutdown` of tidb when the tiproxy is enabled
	DefaultTidbGracefulShutdownWaitSeconds int64 = 15
	// DefaultTidbGracefulShutdownWaitSecondsV2 is same as DefaultTidbGracefulShutdownWaitSeconds, but use 30 seconds.
	DefaultTidbGracefulShutdownWaitSecondsV2 int64 = 30
	// TiDBGracefulShutdownWaitSecondsKey refer to https://docs.pingcap.com/tidb/stable/tidb-configuration-file/#graceful-wait-before-shutdown-new-in-v50
	TiDBGracefulShutdownWaitSecondsKey string = "graceful-wait-before-shutdown"
)

const (
	// AWS
	AWSVolumeTypeGP3 = "gp3"
	AWSVolumeTypeGP2 = "gp2"
	AWSVolumeTypeIO1 = "io1"
	AWSVolumeTypeIO2 = "io2"

	// GCP, https://cloud.google.com/compute/docs/disks#pdspecs
	GCPVolumeTypePDStandard = "pd-standard"
	GCPVolumeTypePDBalanced = "pd-balanced"
	GCPVolumeTypePDSSD      = "pd-ssd"
	GCPVolumeTypePDExtreme  = "pd-extreme"

	// Azure
	AZUREVolumeTypeStandard_LRS_ALIAS = "standardlrs"
	AZUREVolumeTypeStandard_LRS       = "Standard_LRS"
	AZUREVolumeTypePremiumV2          = "premiumv2"
	AZUREVolumeTypeUltraSSD           = "ultrassd"
)

const (
	CloudDiskStorageClassName     = "cloud-ssd"
	LocalDiskStorageClassName     = "local-ssd"
	DefaultStorageClassName       = "cloud-ssd"
	PDGp3StorageClassName         = "pd-gp3"
	TiKVGp3StorageClassName       = "tikv-gp3"
	TiFlashGp3StorageClassName    = "tiflash-gp3"
	TiCDCGp3StorageClassName      = "ticdc-gp3"
	ImportGp3StorageClassName     = "import-gp3"
	ImportGp3IOPS                 = 16000 // the infra-api "github.com/tidbcloud/infra-api/pkg/k8s" package define the iops and throughput as string, so we re-define them as integer here
	ImportGp3ThroughputMBps       = 1000
	MetricsAgentStorageClassName  = "o11y-metric-agent"
	MetricsAgentGp3IOPS           = 3000
	MetricsAgentGp3ThroughputMBps = 125
	TiCDCGp3IOPS                  = 4000
	TiCDCGp3ThroughputMBps        = 400

	AWS_ACCESS_KEY_ENV_VAR string = "AWS_ACCESS_KEY_ID"
	AWS_SECRET_KEY_ENV_VAR string = "AWS_SECRET_ACCESS_KEY" // #nosec G101
	GOMEMLIMIT                    = "GOMEMLIMIT"
)

const (
	// O11yInfraAPIVendor is used for o11y infra openapi requests, which can not identify "eks" if we pass `Network.Spec.Provider`.
	O11yInfraAPIVendor = "aws"
	DefaultMaxWaitSecs = 120
	// O11yClusterEndpointAnnotationKeyPrefix is the prefix of the annotation key for cluster endpoint,
	// which is added to a Network CR.
	O11yClusterEndpointAnnotationKeyPrefix = "o11y.cloud.pingcap.com/endpoint-name"
	O11yVersionAnnotationKey               = "o11y.cloud.pingcap.com/version"
)

const (
	SQLEndpointTargetPort = 4000
)

const (
	PriorityClasName  = "tidb-component-critical"
	NodeTypeDedicated = "Dedicated"
)

func O11yClusterEndpointAnnotationKey(suffix string) string {
	return O11yClusterEndpointAnnotationKeyPrefix + "-" + suffix
}

// taint keys and values
const (
	TaintEffectNoSchedule          = "NO_SCHEDULE"
	TaintEffectNoScheduleForAliyun = "NoSchedule"
	TaintEffectNoScheduleForAKS    = "NoSchedule"

	TaintKeyDedicated = "dedicated"
	TaintValueWorker  = "worker"
	TaintValueShared  = "shared"
	TaintValueO11y    = "o11y"

	TaintKeyHasLocalDisk = "has-local-disk"
	TaintValueTrue       = "true"
)
