package cluster

import (
	"time"

	agentv1 "github.com/tidbcloud/observability/agent-control-server/api/v1"

	"github.com/tidbcloud/infra-provider/pkg/consts"
)

// ShouldWaitForReady returns true if the cluster's status is not same as expectedPhase and the maxWaitSecs has not been reached.
func ShouldWaitForReady(cluster *agentv1.O11yCluster, expectedPhase string, maxWaitSecs int) bool {
	if maxWaitSecs <= 0 {
		maxWaitSecs = consts.DefaultMaxWaitSecs
	}

	if (cluster.Status.Phase != expectedPhase) && (time.Since(cluster.ObjectMeta.CreationTimestamp.Time) <= time.Duration(maxWaitSecs)*time.Second) {
		return true
	}

	return false
}
