package runtimegrpc

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/connectivity"
)

// runtimeConnectionReady both reports readiness and drives an idle gRPC
// connection back into its connection loop. A server graceful stop can leave
// a connection with no subsequent RPC in IDLE; observing GetState alone would
// then make process readiness permanently false after the server recovers.
func runtimeConnectionReady(connection *grpc.ClientConn) bool {
	if connection == nil {
		return false
	}
	if connection.GetState() == connectivity.Idle {
		connection.Connect()
	}
	return connection.GetState() == connectivity.Ready
}
