package api

import (
	"context"

	dataflowng "github.com/tidbcloud/dataflow-service-ng/idl/pbgen/proto/consoleapi"
	"github.com/tidbcloud/dataflow-service/idl/pbgen/proto/dataflow"
	ccapi "github.com/tidbcloud/devops/api/cloudconfig"
)

type TicdcMetaService interface {
	// ListInternalChangefeeds lists full, non-sensitive changefeed details from
	// the Dataflow service selected by the source TiDB cluster type.
	ListInternalChangefeeds(ctx context.Context, param ListInternalChangefeedsParam) (*ccapi.ListInternalChangefeedsResp, error)
	// GetInternalChangefeed resolves a kernel ID to its full, non-sensitive
	// business detail and source TiDB cluster.
	GetInternalChangefeed(ctx context.Context, param GetInternalChangefeedParam) (*GetInternalChangefeedResult, error)

	RestartChangefeed(ctx context.Context, in *dataflow.RestartChangefeedRequest) error
	GetInternalTiCDCCluster(ctx context.Context, in *dataflow.GetInternalTiCDCClusterRequest) (*dataflow.InternalTiCDCCluster, error)
	RestartTiCDCCluster(ctx context.Context, in *dataflow.RestartTiCDCClusterRequest) error

	// Ng TiCDC related
	RestartNgChangefeed(ctx context.Context, in *dataflowng.RestartChangefeedRequest) error
	GetInternalNgTiCDCCluster(ctx context.Context, in *dataflowng.GetInternalTiCDCClusterRequest) (*dataflowng.InternalTiCDCCluster, error)
	RestartNgTiCDCCluster(ctx context.Context, in *dataflowng.RestartTiCDCClusterRequest) error
}

// ListInternalChangefeedsParam identifies the source TiDB cluster and the
// Dataflow architecture that owns its changefeeds.
type ListInternalChangefeedsParam struct {
	TiDBClusterID uint64
	ClusterType   string
}

// GetInternalChangefeedParam identifies a changefeed by its kernel ID. Numeric
// IDs are used by Dedicated and next-gen; Essential uses the string ID.
type GetInternalChangefeedParam struct {
	ChangefeedID       uint64
	ChangefeedIDString string
	ClusterType        string
}

// GetInternalChangefeedResult contains the safe API detail and its source
// cluster for authorization.
type GetInternalChangefeedResult struct {
	Changefeed    *ccapi.InternalChangefeed
	TiDBClusterID uint64
}
