package biz_changefeed

import (
	"fmt"

	"github.com/shiningrush/fastflow/pkg/entity"
	"github.com/shiningrush/fastflow/pkg/entity/run"
	"github.com/tidbcloud/dataflow-service-ng/app/container"
	"github.com/tidbcloud/dataflow-service-ng/app/workflow"
	"github.com/tidbcloud/dataflow-service-ng/app/workflow/action/biz_changefeed/create"
)

//nolint:gomnd
func GetCreateBizChangefeedDag() (*entity.Dag, []run.Action) {
	actions := []run.Action{
		create.NewCreateOrScaleTiCDCClusterAction(
			container.Global().BizChangefeedScheduler,
		),
		create.NewCreateChangefeedAction(
			container.Global().BizChangefeedDownstreamFactory,
			container.Global().BizChangefeedRepo,
			container.Global().RegionalTiCDCChangefeedModel,
			container.Global().MgmtSvcGrpcClient,
		),
		create.NewFinalAction(container.Global().BizChangefeedRepo, container.Global().BizChangefeedHooker),
	}

	dag := &entity.Dag{
		BaseInfo: entity.BaseInfo{
			ID: workflow.DagCreateBizChangefeed,
		},
		Name: workflow.DagCreateBizChangefeed,
		Vars: entity.DagVars{
			workflow.KeyBizChangefeedID: {},
		},
		Status: entity.DagStatusNormal,
		Tasks: []entity.Task{
			{
				ID:         workflow.ActionBizChangefeedCreateOrScaleTiCDCCluster,
				ActionName: workflow.ActionBizChangefeedCreateOrScaleTiCDCCluster,
				Params: map[string]interface{}{
					workflow.KeyBizChangefeedID: fmt.Sprintf("{{%v}}", workflow.KeyBizChangefeedID),
				},
				TimeoutSecs: 60 * 60,
			},
			{
				ID:         workflow.ActionBizChangefeedCreateChangefeed,
				ActionName: workflow.ActionBizChangefeedCreateChangefeed,
				Params: map[string]interface{}{
					workflow.KeyBizChangefeedID: fmt.Sprintf("{{%v}}", workflow.KeyBizChangefeedID),
				},
				TimeoutSecs: 10 * 60,
				DependOn:    []string{workflow.ActionBizChangefeedCreateOrScaleTiCDCCluster},
			},
			{
				ID:         workflow.ActionBizChangefeedCreateFinalStep,
				ActionName: workflow.ActionBizChangefeedCreateFinalStep,
				Params: map[string]interface{}{
					workflow.KeyBizChangefeedID: fmt.Sprintf("{{%v}}", workflow.KeyBizChangefeedID),
				},
				TimeoutSecs: 3 * 60,
				DependOn:    []string{workflow.ActionBizChangefeedCreateChangefeed},
			},
		},
	}
	return dag, actions
}
