package dag

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

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

func RestoreClusterDag() *entity.Dag {
	dag := &entity.Dag{
		BaseInfo: entity.BaseInfo{
			ID: common.RestoreCluster,
		},
		Name:   common.RestoreCluster,
		Status: entity.DagStatusNormal,
		Vars: map[string]entity.DagVar{
			common.KeyRequest:       {},
			workflow.KeyTraceId:     {},
			workflow.KeyRequestMeta: {},
		},
		Tasks: []entity.Task{
			// it asume the cluster is already created and available which granteed by the upper-level service
			{
				ID:         action.CreateLightweightRestore,
				ActionName: action.CreateLightweightRestore,
			},
			// after the restore is done, execute post-restore actions
			{
				ID:         action.PostLightweightRestoreActions,
				ActionName: action.PostLightweightRestoreActions,
				DependOn:   []string{action.CreateLightweightRestore},
			},
			// wait for restore to be done, then clean up restore resources
			{
				ID:         action.DeleteLightweightRestore,
				ActionName: action.DeleteLightweightRestore,
				DependOn:   []string{action.PostLightweightRestoreActions},
			},
			{
				ID:         action.MarkLightweightRestoreSuccess,
				ActionName: action.MarkLightweightRestoreSuccess,
				DependOn:   []string{action.PostLightweightRestoreActions},
			},
		},
	}

	return dag
}
