package service

import (
	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
	"k8s.io/apimachinery/pkg/labels"
)

// buildLabelsForCreatingTiCDC add the labels need when create the cr.
func buildLabelsForCreatingTiCDC(infraProviderType, region, tid, pid, cid string) map[string]string {
	labelMap := buildLabelsForCreatingSinkEndpoint(infraProviderType, region, tid, pid)
	// add cluster id to labels
	labelMap[cloudv1.ClusterTagKey] = cid
	return labelMap
}

// buildLabelsForCreating add the labels need when create the cr.
func buildLabelsForCreatingSinkEndpoint(infraProviderType, region, tid, pid string) map[string]string {
	labelMap := make(map[string]string)
	labelMap[cloudv1.TenantTagKey] = tid
	labelMap[cloudv1.ProjectTagKey] = pid
	labelMap[cloudv1.LabelServiceType] = cloudv1.ServiceTypeDedicated
	labelMap[cloudv1.ProviderTypeLabel] = infraProviderType
	labelMap[cloudv1.RegionLabel] = region
	labelMap["creator"] = "ticdc-service-server"

	return labelMap
}

// buildLabelSetForQuery builds the label set for querying the cdc related resources. like TiCDCSinkEndpoint, TiCDC etc.
// projectId, tenantId, clusterID are the filter conditions only if they are not empty.
func buildLabelSetForQuery(projectId, tenantId, clusterID string) labels.Set {
	labelSet := labels.Set{}
	if projectId != "" {
		labelSet[cloudv1.ProjectTagKey] = projectId
	}
	if tenantId != "" {
		labelSet[cloudv1.TenantTagKey] = tenantId
	}
	if clusterID != "" {
		labelSet[cloudv1.ClusterTagKey] = clusterID
	}
	return labelSet
}
