package clusterconfig

import (
	"context"

	"github.com/tidbcloud/cluster-service-ng/domain/entity"
	configcenter "github.com/tidbcloud/config-center/proto/config_center"
)

type Client interface {
	GetDefaultVersion(ctx context.Context, tenantId string) (string, error)
	GetEffectiveComponentImageTag(ctx context.Context, sharedPool *entity.SharedPool, componentType entity.ComponentType) (string, error)
	CreateClusterMeta(ctx context.Context, sharedPool *entity.SharedPool, tenantId, metaProfileId string) error
	// EnsurePDMicroserviceComponents reconciles Config Center metadata for PD microservice components in the target topology.
	EnsurePDMicroserviceComponents(ctx context.Context, sharedPool *entity.SharedPool) error
	// Notice: make sure called after CreateClusterMeta
	CreateNewComponentConfig(ctx context.Context, sharedPool *entity.SharedPool, componentGroup *entity.Component) error
	DeleteTiKVComponentConfig(ctx context.Context, sharedPool *entity.SharedPool, componentGroup *entity.Component) error
	AddBRComponentsToClusterMeta(ctx context.Context, sharedPool *entity.SharedPool, tenantId, metaProfileId string) error
	AddExportComponentsToClusterMeta(ctx context.Context, tidbCluster *entity.TiDBCluster) error

	// CreateTiDBClusterMeta creates the logical cluster meta in config center
	// It derives tidb/tiproxy components and tiproxy config from sharedpool template
	// It also creates tidb-default config file derived from sharedpool tidb template
	CreateTiDBClusterMeta(ctx context.Context, sharedPool *entity.SharedPool, tidbCluster *entity.TiDBCluster) error
	CreateTiDBGroupConfig(ctx context.Context, tidbGroup *entity.TiDBGroup) error
	DeleteClusterMeta(ctx context.Context, sharedPoolId string) error
	DeleteTiDBClusterMeta(ctx context.Context, tidbClusterId string) error
	DeleteTiDBGroupConfig(ctx context.Context, tidbClusterId, tidbGroupId string) error

	GetComponentVersionAndConfig(ctx context.Context, sharedPool *entity.SharedPool, component *entity.Component) (string, *entity.ComponentConfiguration, error)
	GetDMComponentVersionAndConfig(ctx context.Context, sharedPool *entity.SharedPool) (string, *entity.ComponentConfiguration, error)

	//Notice: will init config and version if not exist for compatibility with old sharedpool
	GetBRComponentVersionAndConfig(ctx context.Context, sharedPool *entity.SharedPool, tenantId string, componentType entity.ComponentType) (string, *entity.ComponentConfiguration, error)
	GetExportComponentVersionAndConfig(ctx context.Context, tidbCluster *entity.TiDBCluster, componentType entity.ComponentType) (string, *entity.ComponentConfiguration, error)

	GetClusterInitSqlStmts(ctx context.Context, sharedPoolId string) (string, error)
	GetClusterTiDBSemConfig(ctx context.Context, sharedPoolId string) (string, error)

	GetTiDBClusterVersion(ctx context.Context, tidbGroup *entity.TiDBCluster) (string, error)
	GetTiDBClusterVersionAndConfig(ctx context.Context, tidbGroup *entity.TiDBGroup, componentType entity.ComponentType) (string, *entity.ComponentConfiguration, error)

	GetClient() configcenter.ConfigCenterServiceClient
}
