package tidbcluster

import (
	"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
)

// GetTidbClusterCondition returns the condition with the provided type.
func GetTidbClusterCondition(tc *v1alpha1.TidbCluster, condType v1alpha1.TidbClusterConditionType) *v1alpha1.TidbClusterCondition {
	for i := range tc.Status.Conditions {
		c := tc.Status.Conditions[i]
		if c.Type == condType {
			return &c
		}
	}
	return nil
}

// GetTidbClusterReadyCondition extracts the tidbcluster ready condition from the given status and returns that.
// Returns nil if the condition is not present.
// https://github.com/tidbcloud/infra-api/blob/4e3f50edd991048e7b8f7c17793debe650c694ba/pkg/pingcap/apis/v1alpha1/tidbcluster.go#L534
func GetTidbClusterReadyCondition(tc *v1alpha1.TidbCluster) *v1alpha1.TidbClusterCondition {
	return GetTidbClusterCondition(tc, v1alpha1.TidbClusterReady)
}
