package cdccluster

import (
	"context"

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

	cdcv1 "github.com/tidbcloud/ticdc-service-ng/api/v1"
)

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

// Provider 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, tag string)
	SetUpstreamCluster(namespace string, name string)
	SetTomlConfig(conf string) error
	SetConfigField(key string, value interface{}) error
	SetNodeSelector(labelSelector map[string]string)
	SetRequest(cpuCore, memoryGi uint32)
	SetStorage(size, vac 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)
}

type Node struct {
	InstanceType string
	K8sVersion   string
	TaintValue   string
}
