package container

import (
	"github.com/shiningrush/fastflow"
	"github.com/tidbcloud/metrics-integration/global/internal/infrastructure/config"
	"github.com/tidbcloud/metrics-integration/global/internal/infrastructure/dataplane"
	"github.com/tidbcloud/metrics-integration/global/internal/infrastructure/db"
	"github.com/tidbcloud/metrics-integration/global/internal/infrastructure/di"
	"github.com/tidbcloud/metrics-integration/global/internal/infrastructure/encryptor"
	"github.com/tidbcloud/metrics-integration/global/internal/infrastructure/workflow"
)

func InitDependencies() {
	// init global config
	di.MustProvide(func() *config.GlobalConfig { return config.Global() })
	// init fastflow as workflow framework
	if !config.Global().DebugConfig.DisableServerWorkflowCli {
		di.MustProvide(workflow.NewWorkflowInitialOption)
		// register the workflow client
		_ = di.DiCall(func(_ *fastflow.InitialOption) {})
	}

	// init k8s rest config pool
	_ = di.DiCall(func(cfg *config.GlobalConfig) {
		dataplane.InitRestConfigs(cfg.DataplaneConfig)
	})

	// init metadb
	di.MustProvide(db.NewGormDB)
	// init encryptor
	di.MustProvide(encryptor.NewEncryptor)
}
