package biz_changefeed

import (
	"context"

	"github.com/tidbcloud/dataflow-service-ng/app/models/domain"
	"github.com/tidbcloud/dataflow-service-ng/app/repo/entity"
	"github.com/tidbcloud/dataflow-service-ng/app/utils"
	"github.com/tidbcloud/pkgv2/bizerr"
)

//nolint:interfacebloat
type BizChangefeedModel interface {
	GetBizChangefeed(
		ctx context.Context, req *domain.GetBizChangefeedReq,
	) (*domain.GetBizChangefeedResp, bizerr.BizError)
	ListBizChangefeeds(
		ctx context.Context, req *domain.ListBizChangefeedsReq,
	) (*domain.ListBizChangefeedsResp, bizerr.BizError)
	CreateBizChangefeed(
		ctx context.Context, req *domain.CreateBizChangefeedReq,
	) (*domain.CreateBizChangefeedResp, bizerr.BizError)
	DeleteBizChangefeed(
		ctx context.Context, req *domain.DeleteBizChangefeedReq,
	) (*domain.DeleteBizChangefeedResp, bizerr.BizError)
	PauseBizChangefeed(ctx context.Context, req *domain.PauseBizChangefeedReq) bizerr.BizError
	ResumeBizChangefeed(ctx context.Context, req *domain.ResumeBizChangefeedReq) bizerr.BizError
	EditBizChangefeed(ctx context.Context, req *domain.EditBizChangefeedReq) bizerr.BizError
	ApplyStoppedBizChangefeedConfig(
		ctx context.Context, req *domain.ApplyStoppedBizChangefeedConfigReq,
	) bizerr.BizError
	ScaleBizChangefeed(
		ctx context.Context, req *domain.ScaleBizChangefeedReq,
	) (*domain.ScaleBizChangefeedResp, bizerr.BizError)
	TestBizChangefeed(ctx context.Context, req *domain.TestBizChangefeedReq) bizerr.BizError
	GetClusterBizChangefeedRCU(
		ctx context.Context, req *domain.GetClusterBizChangefeedRCUReq,
	) (*domain.GetClusterBizChangefeedRCUResp, bizerr.BizError)
	CalBizChangefeedFee(
		ctx context.Context, req *domain.CalBizChangefeedFeeReq,
	) (*domain.CalBizChangefeedFeeResp, bizerr.BizError)
	ListBizChangefeedSpecifications(
		ctx context.Context, req *domain.ListBizChangefeedSpecificationsReq,
	) (*domain.ListBizChangefeedSpecificationsResp, bizerr.BizError)
	// GetChangefeedDetail returns the ticdc kernel changefeed configuration the for E2E test cases
	GetChangefeedDetail(ctx context.Context,
		req *domain.GetBizChangefeedDetailReq) (*domain.GetBizChangefeedDetailResp, bizerr.BizError)
	// GetTiCDCCluster return the ticdc cluster deployment topology detail information for E2E test cases
	GetTiCDCCluster(ctx context.Context,
		req *domain.GetBizChangefeedClusterReq) (*domain.GetBizChangefeedClusterResp, bizerr.BizError)
	ListTiCDCClusters(ctx context.Context,
		req *domain.ListTiCDCClusterReq) (*domain.ListTiCDCClusterResp, bizerr.BizError)
	EditBizChangefeedForOps(ctx context.Context, bizChangefeedID uint64) bizerr.BizError
	DescribeSchemaTable(ctx context.Context,
		req *domain.DescribeSchemaTableReq) (*domain.DescribeSchemaTableResp, bizerr.BizError)
	DescribeAdminProfile(
		ctx context.Context, req *domain.DescribeAdminProfileReq,
	) (*domain.DescribeAdminProfileResp, bizerr.BizError)
}

type BizChangefeedHooker interface {
	HandleBizChangefeedEvent(
		ctx context.Context, event entity.DataflowEventType, userID uint64, bizChangefeedEntity *entity.BizChangefeed,
	)
}

type DownstreamAdaptor interface {
	TestConnection(ctx context.Context, cluster *utils.Cluster, downstreamParams interface{}) bizerr.BizError
	PreCheckChangefeedParameters(
		ctx context.Context, cluster *utils.Cluster, downstreamParams interface{},
	) bizerr.BizError
	EncryptPasswordInPlace(ctx context.Context, downstreamParams interface{}) bizerr.BizError
	AssembleChangefeedConfig(
		ctx context.Context, cluster *utils.Cluster, bizCf *entity.BizChangefeed,
	) (*domain.TiCDCChangefeedConfig, bizerr.BizError)
	CompleteEditParams(
		ctx context.Context, editDownstreamParams interface{}, currentDownstreamParams string,
	) bizerr.BizError
}

type BizChangefeedMeteringWorker interface {
	GenBillingRecordsByCluster(ctx context.Context) error
}

type BizChangefeedMetricsWorker interface {
	UpdateChangefeedMetrics(ctx context.Context) error
}
