package dag

import (
	"fmt"

	"github.com/tidbcloud/fastflow/pkg/entity"

	"github.com/tidbcloud/tidb-management-service/dedicated-global-service/domain/service/workflow/action"
	"github.com/tidbcloud/tidb-management-service/dedicated-global-service/domain/service/workflow/common"
	"github.com/tidbcloud/tidb-management-service/utilities/workflow"
)

func DeleteClusterDag() *entity.Dag {
	dag := &entity.Dag{
		BaseInfo: entity.BaseInfo{
			ID: common.DeleteCluster,
		},
		Name:   common.DeleteCluster,
		Status: entity.DagStatusNormal,
		Vars: map[string]entity.DagVar{
			workflow.KeyTraceId:             {},
			common.KeyClusterId:             {},
			common.KeyTidbGroupIds:          {},
			common.KeyPrivateLinkServiceIds: {},
		},
		Tasks: []entity.Task{
			{
				ID:         action.DeletePrivateLinkService,
				ActionName: action.DeletePrivateLinkService,
				Params: map[string]any{
					common.KeyClusterId: fmt.Sprintf("{{%s}}", common.KeyClusterId),
				},
			},
			{
				ID:         action.DeleteTidbGroup,
				ActionName: action.DeleteTidbGroup,
				Params: map[string]any{
					common.KeyClusterId: fmt.Sprintf("{{%s}}", common.KeyClusterId),
				},
				DependOn: []string{action.DeletePrivateLinkService},
			},
			{
				ID:         action.DeleteGKEHeterogeneousBeforeDeleteClusterActionName,
				ActionName: action.DeleteGKEHeterogeneousBeforeDeleteClusterActionName,
				Params: map[string]any{
					common.KeyClusterId: fmt.Sprintf("{{%s}}", common.KeyClusterId),
				},
				DependOn: []string{action.DeleteTidbGroup},
			},
			{
				ID:         action.DeleteCluster,
				ActionName: action.DeleteCluster,
				Params: map[string]any{
					common.KeyClusterId: fmt.Sprintf("{{%s}}", common.KeyClusterId),
				},
				DependOn: []string{action.DeleteGKEHeterogeneousBeforeDeleteClusterActionName},
			},
			{
				ID:         action.DeleteClusterMeta,
				ActionName: action.DeleteClusterMeta,
				Params: map[string]any{
					common.KeyClusterId: fmt.Sprintf("{{%s}}", common.KeyClusterId),
				},
				DependOn: []string{action.DeleteCluster},
			},
		},
	}

	return dag
}
