package console

import (
	"github.com/tidbcloud/core-svc/idl/pbgen/proto/core"
	"github.com/tidbcloud/dataflow-service/app/internal/feature_gate"
	"github.com/tidbcloud/dataflow-service/app/repo/entity"
	"github.com/tidbcloud/dataflow-service/idl/pbgen/proto/dataflow"
	"github.com/tidbcloud/dataflow-service/internal/config"
)

func isMultiTiCDCClustersEnabled(
	featureGate feature_gate.FeatureGate,
	featureGateReq *feature_gate.QueryFeatureGateReq,
	cluster *core.Cluster,
	downstreamType dataflow.ConnectorType,
) bool {
	return featureGate.IsFeatureEnabled(featureGateReq, feature_gate.MultiTiCDCClusters) &&
		config.Global().ChangefeedConfig.MultiTiCDCClustersFeatureGate.IsEnabled(
			cluster.CloudProviderName, downstreamType)
}

func getBizChangefeedDeployType(
	featureGate feature_gate.FeatureGate,
	cluster *core.Cluster,
	downstreamType dataflow.ConnectorType,
) entity.TiCDCClusterDeployType {
	deployType := entity.TiCDCClusterDeployTypeShared
	featureGateReq := &feature_gate.QueryFeatureGateReq{
		TenantID:  cluster.TenantId,
		ProjectID: cluster.ProjectId,
		ClusterID: cluster.Id,
	}
	if isMultiTiCDCClustersEnabled(featureGate, featureGateReq, cluster, downstreamType) {
		deployType = entity.TiCDCClusterDeployTypeDedicated
	}
	return deployType
}
