package cases

import (
	"fmt"

	"github.com/tidbcloud/observability/test/webconsolee2e/cases/dedicated"
	"github.com/tidbcloud/observability/test/webconsolee2e/cases/nextgen"
	"github.com/tidbcloud/observability/test/webconsolee2e/cases/shared"
	"github.com/tidbcloud/observability/test/webconsolee2e/framework"
)

// ClusterType represents the type of cluster
type ClusterType string

const (
	ClusterTypeDedicated ClusterType = "dedicated"
	ClusterTypeShared    ClusterType = "shared"
	ClusterTypeNextgen   ClusterType = "nextgen"
	ClusterTypeBYOC      ClusterType = "byoc"
)

// ValidClusterTypes returns the list of valid cluster types
func ValidClusterTypes() []ClusterType {
	return []ClusterType{ClusterTypeDedicated, ClusterTypeShared, ClusterTypeNextgen, ClusterTypeBYOC}
}

// IsValidClusterType checks if the given cluster type is valid
func IsValidClusterType(ct string) bool {
	for _, valid := range ValidClusterTypes() {
		if ClusterType(ct) == valid {
			return true
		}
	}
	return false
}

// RegisterCases registers test cases based on cluster type
func RegisterCases(fw *framework.TestFramework, clusterType ClusterType) error {
	switch clusterType {
	case ClusterTypeDedicated:
		// Check if new path testing is enabled
		if fw.GetConfig().EnableNewPath {
			dedicated.RegisterDedicatedCasesWithNewPath(fw)
		} else {
			dedicated.RegisterDedicatedCases(fw)
		}
	case ClusterTypeShared:
		// Check if new path testing is enabled
		if fw.GetConfig().EnableNewPath {
			shared.RegisterSharedCasesWithNewPath(fw)
		} else {
			shared.RegisterSharedCases(fw)
		}
	case ClusterTypeNextgen, ClusterTypeBYOC:
		// BYOC reuses nextgen test cases with different bizType
		// Check if new path testing is enabled
		if fw.GetConfig().EnableNewPath {
			nextgen.RegisterNextgenCasesWithNewPath(fw)
		} else {
			nextgen.RegisterNextgenCases(fw)
		}
	default:
		return fmt.Errorf("unknown cluster type: %s, valid types are: %v", clusterType, ValidClusterTypes())
	}
	return nil
}
