package biz_changefeed

import (
	"fmt"

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

//nolint:gomnd
func GetScaleBizChangefeedDag() (*entity.Dag, []run.Action) {
	actions := []run.Action{
		scale.NewScaleTiCDCClusterAction(
			container.Global().BizChangefeedRepo,
			container.Global().BizChangefeedSchedulerFactory,
		),
		scale.NewFinalAction(container.Global().BizChangefeedRepo, container.Global().BizChangefeedHooker),
	}

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