package cluster

import (
	"context"

	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/entity"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/service/serverless"
)

// GetClusterByZeroID validates the given zero ID and returns the cluster it identifies.
func (svc *service) GetClusterByZeroID(ctx context.Context, zeroId string) (*entity.Cluster, error) {
	ctx, span := serverless.Tracer.Start(ctx, "ClusterService.GetClusterByZeroID")
	defer span.End()

	clusterId, err := svc.parseZeroId(ctx, zeroId)
	if err != nil {
		return nil, err
	}

	return svc.GetCluster(ctx, clusterId, entity.ClusterViewClusterViewFull)
}
