package aws

import (
	"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"
	bucket_delete "github.com/tidbcloud/dataflow-service/app/workflow/action/bucket/del"
	"github.com/tidbcloud/dataflow-service/app/workflow/action/bucket/del/aws"
)

//nolint:funlen,gomnd
func GetDeleteBucketDag() (*entity.Dag, []run.Action) {
	actions := []run.Action{
		bucket_delete.NewDeletePreCheckAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
		),
		bucket_delete.NewStopOtherDagInsAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
			container.Global().WorkflowModel,
		),
		aws.NewDeleteFromAWSAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
			container.Global().AWSBucketManagerModel,
		),
		bucket_delete.NewMarkDeletedAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
		),
	}

	dag := &entity.Dag{
		BaseInfo: entity.BaseInfo{
			ID: workflow.DagDeleteBucketAWS,
		},
		Name: workflow.DagDeleteBucketAWS,
		Vars: entity.DagVars{
			workflow.KeyBucketID: {},
		},
		Status: entity.DagStatusNormal,
		Tasks: []entity.Task{
			{
				ID:          workflow.ActionDeleteBucketPreCheck,
				ActionName:  workflow.ActionDeleteBucketPreCheck,
				TimeoutSecs: 60 * 3,
			},
			{
				ID:          workflow.ActionDeleteBucketStopOtherDagIns,
				ActionName:  workflow.ActionDeleteBucketStopOtherDagIns,
				TimeoutSecs: 60,
				DependOn:    []string{workflow.ActionDeleteBucketPreCheck},
			},
			{
				ID:          workflow.ActionDeleteBucketDeleteFromAWS,
				ActionName:  workflow.ActionDeleteBucketDeleteFromAWS,
				TimeoutSecs: 60 * 2,
				DependOn: []string{
					workflow.ActionDeleteBucketStopOtherDagIns,
				},
			},
			{
				ID:          workflow.ActionDeleteBucketMarkDeleted,
				ActionName:  workflow.ActionDeleteBucketMarkDeleted,
				TimeoutSecs: 30,
				DependOn: []string{
					workflow.ActionDeleteBucketDeleteFromAWS,
				},
			},
		},
	}
	return dag, actions
}
