package util

import "fmt"

// NodeLabelKeyForTiDB returns the key of the label uesed fot tidb node
func NodeLabelKeyForTiDB(id int64) string {
	return fmt.Sprintf("%d-tidb", id)
}

// NodeLabelKeyForTiKV returns the key of the label uesed fot tikv node
func NodeLabelKeyForTiKV(id int64) string {
	return fmt.Sprintf("%d-tikv", id)
}

// NodeLabelKeyForPD returns the key of the label uesed fot pd node
func NodeLabelKeyForPD(id int64) string {
	return fmt.Sprintf("%d-pd", id)
}

// NodeLabelKeyForTest returns the key of the label uesed fot test node
func NodeLabelKeyForTest(id int64) string {
	return fmt.Sprintf("%d-test", id)
}

// CleanIDCLabels returns labels without idc label
// delete labels["idc"]
func CleanIDCLabels(labels map[string]string) map[string]string {
	if labels == nil {
		return make(map[string]string)
	}

	delete(labels, "idc")

	return labels
}

// GetLabels gets label by labelName, if not found, return nil
func GetLabels(labels map[string]string, labelName string) map[string]string {
	genLabels := make(map[string]string)
	if labels == nil {
		return genLabels
	}
	label, ok := labels[labelName]
	if ok {
		genLabels[labelName] = label
	}
	return genLabels
}
