package cdccluster

import (
	"context"

	cdcv1 "github.com/tidbcloud/ticdc-service/api/v1"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/types"
	"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
	TiCDCDefaultDirName = "sort-kv"
	TiCDCDefaultDirPath = "/var/lib/ticdc"
)

// CdcClusterProvider is the provider to manage CdcCluster
type Provider interface {
	Init(string, string) // init build a basic CdcCluster CR
	SetReplicas(replicas int32)
	SetVersion(baseImage string, version string)
	SetUpstreamCluster(namespace string, name string)
	SetTomlConfig(conf string) error
	SetConfigField(key string, value interface{}) error
	SetNodeSelector(labelSelector map[string]string)
	SetStorage(class string, size string)
	GetClusterStatus(ctx context.Context, cli client.Client) (*cdcv1.TiCDCStatus, error)
	// NeedReschedule indicates whether the existing cdc cluster need to be rescheduled to new nodes
	NeedReschedule(ctx context.Context, cli client.Client, desiredNode *Node) (bool, error)
	// Rescheduled indicates whether the cdc cluster pods are all rescheduled on the desired nodes
	Rescheduled(ctx context.Context, cli client.Client) (bool, error)
	ApplyCR(ctx context.Context, cli client.Client) error
	DeleteCR(ctx context.Context, cli client.Client, name types.NamespacedName) error
	SetRestart(restartedAt string)
	SetTolerations(tolerations []corev1.Toleration)
	EnableMountCertificate(ctx context.Context, sidecarImage string, cli client.Client) error
	SetServiceAccount(ctx context.Context, cli client.Client) error
}

type Node struct {
	InstanceType string
	K8sVersion   string
	TaintValue   string
}
