package config

import (
	"fmt"

	restclient "k8s.io/client-go/rest"
)

const (
	PublicMode      = "public"
	InnerMode       = "inner"
	PrivatelinkMode = "privatelink"
)

const (
	CONNECTION_STATUS_EXTER_WARN   = "exter_warn"   // warn caused by user, no matter to us
	CONNECTION_STATUS_INNER_WARN   = "inner_warn"   // warn may be caused by ourselves, no impact on user
	CONNECTION_STATUS_DESIGN_ERROR = "design_error" // error caused by design, may impact on user
	CONNECTION_STATUS_INNER_ERROR  = "inner_error"  // error caused by ourselves, significant impact on user
	CONNECTION_STATUS_TIDB_ERROR   = "tidb_error"
	CONNECTION_STATUS_NORMAL       = "normal"
	CONNECTION_STATUS_MISSMATCH    = "missmatch"
	CONNECTION_STATUS_CANCEL       = "cancel"
)

// TLSConfig is used to establish TLS connection.
type TLSConfig struct {
	CA         string
	Cert       string
	Key        string
	MinVersion string
}

// TrafficIPAllowListConfig is used to allow traffic from certain source.
type TrafficIPAllowListConfig []string

func (l *TrafficIPAllowListConfig) String() string {
	return fmt.Sprint(*l)
}

// Set is used to set the flag value.
func (l *TrafficIPAllowListConfig) Set(value string) error {
	*l = append(*l, value)
	return nil
}

// Config is used to configure a gateway.
type Config struct {
	Address                    string
	TLS                        TLSConfig
	ClusterTLS                 TLSConfig
	SQLTLS                     TLSConfig
	InfraRedisClientTLSConfig  TLSConfig
	RequireBackendTLS          bool
	EnableCompression          bool
	AWSSDKLogMode              string
	InfraRedisAddr             string
	InfraClusterTable          string
	OtsInstanceName            string
	Region                     string
	InfraConfig                *restclient.Config
	LocalConfig                *restclient.Config
	CloudProviderType          string
	KubeClusterName            string
	GatewayMode                string
	DevelopMode                bool
	TrafficIPAllowList         []string
	TLSOnly                    bool
	TLSOnlySkipUserPrefixes    []string // Users with these prefixes are exempt from TLS requirement
	MaxIdleSeconds             uint
	E2EEnv                     bool
	PushTrafficMetricsAddr     string
	PushTrafficMetricsInterval int
	OnlyForZR                  bool
	TiDBServerVersion          string

	EnableInfraMysqlClient bool
	InfraRdsSecretArn      string
	CacheServerAddr        string
	FrontendReadTimeout    int
}
