package utils

import "fmt"

const (
	// TODO: use image in private registry
	// RegistryPrefix is the default public docker image registry prefix.
	RegistryPrefix = "gcr.io/pingcap-public/dbaas"
	// ThirdPartyRegistryPrefix is the registry prefix for the third
	// party images, e.g. Prometheus
	ThirdPartyRegistryPrefix = "gcr.io/pingcap-public/third-party"

	// GottyImage is the name of gotty image.
	GottyImage = "gotty"

	// BusyboxImage is the name of busybox image.
	BusyboxImage = "busybox"

	// HealthCheckerImage is the name of tidb health-checker sidecar image.
	HealthCheckerImage = "health-checker"

	// GracefulShutdownTiDBWebhookImage is the name of graceful-shutdown-tidb-webhook image.
	GracefulShutdownTiDBWebhookImage = "graceful-shutdown-tidb-webhook"

	// PrometheusImage is the name of prometheus image.
	PrometheusImage = "prometheus"

	// TiDBMonitorReloaderImage is the name of tidb-monitor-reloader image.
	TiDBMonitorReloaderImage = "tidb-monitor-reloader"

	// TiDBMonitorInitializerImage is the name of tidb-monitor-initializer image.
	TiDBMonitorInitializerImage = "tidb-monitor-initializer"

	// AdvancedStatefulsetImage is the name of AdvancedStatefulSet controller image.
	AdvancedStatefulsetImage = "advanced-statefulset"

	// MysqlClientImage is the image name that contains python mysql client
	MysqlClientImage = "tnir/mysqlclient"

	// MysqlClientVersion is the version of python mysql client docker image
	MysqlClientVersion = "20201014"
)

var (
	// GottyVersion is the version of GottyImage.
	GottyVersion = "20201216"

	// BusyboxVersion is the version of BusyboxImage.
	BusyboxVersion = "1.31.1"

	// HealthCheckerVersion is the version of HealthCheckerImage.
	HealthCheckerVersion = "20201224"

	// GracefulShutdownTiDBWebhookVersion is the version of GracefulShutdownTiDBWebhookImage.
	GracefulShutdownTiDBWebhookVersion = "20210107"

	// PrometheusVersion is the version of prometheus image.
	PrometheusVersion = "v2.18.1"

	// TiDBMonitorReloaderVersion is the version of tidb-monitor-reloader image.
	TiDBMonitorReloaderVersion = "v1.0.1"

	// AdvancedStatefulsetVersion is the version of AdvancedStatefulsetImage.
	AdvancedStatefulsetVersion = "v0.4.0"

	// BR status addr.
	BRStatusAddr = "0.0.0.0:8089"
)

func GetImage(image, version string) string {
	return fmt.Sprintf("%s:%s", GetBaseImage(image), version)
}

func GetBaseImage(image string) string {
	return fmt.Sprintf("%s/%s", RegistryPrefix, image)
}

func GetThirdPartyImage(image string) string {
	return fmt.Sprintf("%s/%s", ThirdPartyRegistryPrefix, image)
}

func GetGottyImage() string {
	return GetImage(GottyImage, GottyVersion)
}

func GetBusyboxImage() string {
	return GetImage(BusyboxImage, BusyboxVersion)
}

func GetHealthCheckerImage() string {
	return GetImage(HealthCheckerImage, HealthCheckerVersion)
}

func GetGracefulShutdownTiDBWebhookImage() string {
	return GetImage(GracefulShutdownTiDBWebhookImage, GracefulShutdownTiDBWebhookVersion)
}

func GetAdvancedStatefulsetImage() string {
	return GetImage(AdvancedStatefulsetImage, AdvancedStatefulsetVersion)
}

func GetMysqlClientImage() string {
	return fmt.Sprintf("%s:%s", GetThirdPartyImage(MysqlClientImage), MysqlClientVersion)
}
