package dag

import (
	"fmt"

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

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

func NewCreateClusterDag() *entity.Dag {
	dag := &entity.Dag{
		BaseInfo: entity.BaseInfo{
			ID: common.CreateCluster,
		},
		Name:   common.CreateCluster,
		Status: entity.DagStatusNormal,
		Vars: map[string]entity.DagVar{
			workflow.KeyTraceId:     {},
			common.KeyClusterId:     {},
			common.KeyRequestBody:   {},
			common.KeyInitSQLs:      {},
			common.KeyOperationId:   {},
			workflow.KeyRequestMeta: {},
		},
		Tasks: []entity.Task{
			{
				ID:         action.PreCreateCluster,
				ActionName: action.PreCreateCluster,
				Params: map[string]any{
					common.KeyClusterId:   fmt.Sprintf("{{%s}}", common.KeyClusterId),
					common.KeyRequestBody: fmt.Sprintf("{{%s}}", common.KeyRequestBody),
				},
			},
			{
				ID:         action.CreateCluster,
				ActionName: action.CreateCluster,
				Params: map[string]any{
					common.KeyClusterId:   fmt.Sprintf("{{%s}}", common.KeyClusterId),
					common.KeyRequestBody: fmt.Sprintf("{{%s}}", common.KeyRequestBody),
				},
				DependOn: []string{action.PreCreateCluster},
			},
			{
				ID:         action.PostCreateCluster,
				ActionName: action.PostCreateCluster,
				Params: map[string]any{
					common.KeyClusterId: fmt.Sprintf("{{%s}}", common.KeyClusterId),
					common.KeyInitSQLs:  fmt.Sprintf("{{%s}}", common.KeyInitSQLs),
				},
				DependOn: []string{action.CreateCluster},
			},
		},
	}

	return dag
}
