package extratidb

import (
	"context"

	"sigs.k8s.io/controller-runtime/pkg/client"

	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
	"github.com/tidbcloud/infra-provider/pkg/dataplane"
	"github.com/tidbcloud/infra-provider/pkg/gitops"
)

// Handler is the interface that knows how to prepare, check, and delete the extra tidb nodes.
type Handler interface {
	// PrepareNodes creates nodes for the extra tidb at the right AZ.
	// The function call is idempotent.
	PrepareNodes(context.Context, client.Client, gitops.Provider, *cloudv1.Network, *cloudv1.Cluster) (string, error)

	// PrepareNodesV2 creates nodes for the extra tidb at the right AZ.
	// It's for 3-layer arch.
	PrepareNodesV2(context.Context, client.Client, gitops.Provider, dataplane.EnvProvider, *cloudv1.Cluster) (string, error)

	// AreAllNodesReady checks if the extra tidb nodes are ready.
	// The function call is idempotent.
	AreAllNodesReady(context.Context, client.Client, *cloudv1.Cluster) (bool, error)

	// DeleteNodes deletes the extra tidb nodes if the pod does not exist.
	// If the extra tidb pod exists, will return an error.
	// It is safe to call this function even if the extra tidb nodes do not exist.
	// The function call is idempotent.
	DeleteNodes(context.Context, client.Client, *cloudv1.Cluster) error
}
