package config

import (
	"time"

	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
	"k8s.io/client-go/rest"
)

// InfraClientRequirements describes which regional infra clients a manager process needs.
type InfraClientRequirements struct {
	MySQLClient  bool
	LegacyClient bool
	LegacyCache  bool
}

// ResolveInfraClientRequirements resolves primary and double-write client requirements.
func ResolveInfraClientRequirements(enableMySQLClient, enableDoubleWrite bool) InfraClientRequirements {
	return InfraClientRequirements{
		MySQLClient:  enableMySQLClient || enableDoubleWrite,
		LegacyClient: !enableMySQLClient || enableDoubleWrite,
		LegacyCache:  !enableMySQLClient,
	}
}

// Config is manager config.
type Config struct {
	Kubeconfig *rest.Config

	MetricsBindAddress      string
	WebhookPort             int
	CertDir                 string
	InfraRedisClientCertDir string
	HttpServerBindAddress   string
	EnableGrpcReflection    bool
	EnableLeaderElection    bool

	ClusterCAPath   string
	ClusterCertPath string
	ClusterKeyPath  string

	ImportEnableTLS bool

	S3BucketName    string
	S3BackupRoleArn string
	AWSAccountID    string
	AWSSDKLogMode   string
	BaseProxy       string

	Region                   string
	CloudProviderType        string
	KubeClusterName          string
	RemoteWriteUrl           string
	ServerlessLightningImage string
	ImportJobsNamespace      string
	ImportSAName             string
	ImportRoleName           string
	ImportMaxConcurrent      int
	TiDBWorkerNS             string

	KeyspacePoolNs               string
	EncryptKeyspacePoolNs        string
	KeyspacePoolEnableTLS        bool
	EncryptKeyspacePoolEnableTLS bool
	TidbPoolNamespaceList        []string
	TidbPoolGCIntervalList       []time.Duration
	TidbVersionList              []string
	EtcdPrefixList               []string
	EtcdCheckConnPrefix          string
	EtcdEndpoints                string
	ActivateTidbImage            string
	DisableNodeRecover           bool
	DisableTidbReschedule        bool
	DisableNodeRebalance         bool
	DisableNodeDrainer           bool
	DisableRZEvicter             bool
	DisableTidbPodEvicter        bool
	SkipClusterDeleteEtcdAndPd   bool

	KeyspacePoolCreateRatePerSecond float64

	MaxMinStartTsStaleDuration time.Duration

	O11yAgentEnabled         bool
	ObservabilityInfraConfig *cloudv1.ObservabilityInfraConfig
	O11yAgentAccessArn       string
	O11yGlobalClusterID      string

	ExportJobCM        string
	ExportJobNS        string
	DumplingImage      string
	ExportStashingArea string
	ExportDebugMode    bool
	ExportEnableTLS    bool

	AuditLogKmsAliasArn          string
	AuditLogEncryptKeyCiphertext string

	InfraRedisAddr        string
	InfraClusterTable     string
	OtsInstanceName       string
	RocketmqInstanceID    string
	RocketmqEndpoint      string
	RocketmqConsumerGroup string
	RocketmqUsername      string
	RocketmqPassword      string
	ClusterQueueURL       string
	RdsSecretArn          string
	EnableVersionUpdater  bool
	DisableAuditLog       bool
	RdsSecretRegion       string

	EnableInfraMysqlClient bool
	EnableDoubleWrite      bool
	InfraRdsSecretArn      string
	CacheServerAddr        string

	BranchRestoreMode string
}
