package task

import (
	"strings"

	"github.com/tidbcloud/observability/pkg/common/constants"
)

// Deploy types passed to the ETL job manager. The ETL uses this to select the
// source-log layout under the source bucket; "serverless" is the ETL default.
// Valid values must match what the ETL's parseDeployType accepts:
// "serverless", "dedicated", or "premium".
const (
	DeployTypeServerless = "serverless"
	DeployTypeDedicated  = "dedicated"
	// DeployTypePremium maps to the next-gen layout in the ETL:
	// source path = srcPrefix/<clusterID>/logs/<logKind>/ (no tenantID or projectID).
	// Despite the name, this covers TiDB Cloud next-gen/BYOC clusters whose logs are
	// stored at 0/next-gen/<clusterID>/logs/..., not tidbcloud "premium tier" clusters
	// using the dedicated layout.
	DeployTypePremium = "premium"
)

// bizType markers used to classify a cluster's tier. Mirrors the authoritative
// logic in regionalservice.buildStorageObjectPath.
const (
	bizTypeMarkerServerless = "devtier"
	bizTypeMarkerNextGen    = "nextgen"
)

// DeployType classifies a bizType into the ETL deploy type, which selects the
// source-log layout. Mirrors regionalservice.buildStorageObjectPath so the ETL
// reads from the same prefix the log writer produced.
func DeployType(bizType string) string {
	switch {
	case strings.Contains(bizType, bizTypeMarkerServerless):
		return DeployTypeServerless
	case bizType == constants.DefaultByocBizType || strings.Contains(bizType, bizTypeMarkerNextGen):
		return DeployTypePremium
	default:
		return DeployTypeDedicated
	}
}
