package azure

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_create "github.com/tidbcloud/dataflow-service/app/workflow/action/bucket/create"
	"github.com/tidbcloud/dataflow-service/app/workflow/action/bucket/create/azure"
)

//nolint:funlen,gomnd
func GetCreateBucketDag() (*entity.Dag, []run.Action) {
	actions := []run.Action{
		azure.NewCreateBucketAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
			container.Global().AzureBucketManagerModel,
		),
		azure.NewCreateContainerAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
			container.Global().AzureBucketManagerModel,
		),
		azure.NewEnableBucketEncryptionAzureAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
			container.Global().AzureBucketManagerModel,
		),
		bucket_create.NewCreateBucketFinalAction(
			container.Global().TransProvider,
			container.Global().BucketRepo,
		),
	}
	dag := &entity.Dag{
		BaseInfo: entity.BaseInfo{
			ID: workflow.DagCreateBucketAzure,
		},
		Name:   workflow.DagCreateBucketAzure,
		Status: entity.DagStatusNormal,
		Vars: map[string]entity.DagVar{
			workflow.KeyBucketID:               {},
			workflow.KeyBucketEncryptionSwitch: {},
		},
		Tasks: []entity.Task{
			{
				ID:          workflow.ActionCreateBucketAzure,
				ActionName:  workflow.ActionCreateBucketAzure,
				TimeoutSecs: 60 * 3,
			},
			{
				ID:          workflow.ActionCreateContainer,
				ActionName:  workflow.ActionCreateContainer,
				DependOn:    []string{workflow.ActionCreateBucketAzure},
				TimeoutSecs: 30,
			},
			{
				ID:          workflow.ActionEnableBucketEncryptionAzure,
				ActionName:  workflow.ActionEnableBucketEncryptionAzure,
				DependOn:    []string{workflow.ActionCreateContainer},
				TimeoutSecs: 30,
				PreChecks: map[string]*entity.Check{
					workflow.ActionEnableBucketEncryptionAzure: {
						Conditions: []entity.TaskCondition{
							{
								Source: entity.TaskConditionSourceVars,
								Key:    workflow.KeyBucketEncryptionSwitch,
								Values: []string{workflow.ValueBucketEncryptionSwitchTrue},
								Op:     entity.OperatorNotIn,
							},
						},
						Act: entity.ActiveActionSkip,
					},
				},
			},
			{
				ID:         workflow.ActionCreateBucketFinalStep,
				ActionName: workflow.ActionCreateBucketFinalStep,
				DependOn: []string{
					workflow.ActionEnableBucketEncryptionAzure,
				},
				TimeoutSecs: 30,
			},
		},
	}
	return dag, actions
}
