package factory

import (
	"fmt"
	"strings"

	rm "github.com/tidbcloud/aws-shared-provider/pkg/tidbworker/resourcemanager/types"
)

const (
	PoolManagerPrefix = "wp"
)

// WorkerHandle generates the worker handle based on the pool and index.
func WorkerHandle(pool rm.WorkerPool, index int) rm.Worker {
	workerStr := fmt.Sprintf(PoolManagerPrefix+"-%s-%d", pool, index)
	return rm.Worker(workerStr)
}

// WorkerStatusEndpoint generates the worker status endpoint based on the worker handle.
func WorkerStatusEndpoint(worker rm.Worker, namespace string) string {
	return fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcName(worker), namespace, tidbStatusPort)
}

// workerPodName generates the worker pod name based on worker handle and revision.
func workerPodName(worker rm.Worker, revision string) string {
	return strings.ToLower(string(worker) + "-" + revision)
}

// svcName return the service name based on the worker handle.
func svcName(worker rm.Worker) string {
	return strings.ToLower(string(worker))
}
