package biz

import (
	"ai_scheduler/internal/biz/handle/qywx"
	"ai_scheduler/internal/biz/tools_regis"
	"ai_scheduler/internal/config"
	"ai_scheduler/internal/data/impl"
	"ai_scheduler/internal/domain/component"
	"ai_scheduler/internal/domain/component/callback"
	"ai_scheduler/internal/domain/repo"
	"ai_scheduler/internal/domain/workflow"
	"ai_scheduler/internal/pkg"
	"ai_scheduler/internal/pkg/dingtalk"
	"ai_scheduler/internal/pkg/lsxd"
	"ai_scheduler/internal/pkg/utils_ollama"
	"ai_scheduler/internal/pkg/utils_oss"
	"ai_scheduler/internal/tools"
	"ai_scheduler/utils"
	"context"
	"testing"
)

func Test_InitGroup(t *testing.T) {
	run()
	chatId, err := qywxAppBiz.InitGroup(context.Background())
	t.Log(chatId, err)
}

var (
	configConfig   *config.Config
	qywxAppBiz     *QywxAppBiz
	groupConfigBiz *GroupConfigBiz
)

func run() {
	configConfig, _ = config.LoadConfigWithTest()
	// 初始化数据库连接
	db, _ := utils.NewGormDb(configConfig)
	rdb := utils.NewRdb(configConfig)
	botGroupQywxImpl := impl.NewBotGroupQywxImpl(db)
	qywxAuth := qywx.NewAuth(configConfig, rdb)
	group := qywx.NewGroup(botGroupQywxImpl, qywxAuth)
	sessionImpl := impl.NewSessionImpl(db)
	other := qywx.NewOther(qywxAuth)
	repos := repo.NewRepos(sessionImpl, configConfig, rdb)
	pkgRdb := pkg.NewRdb(configConfig)
	redisManager := callback.NewRedisManager(pkgRdb)
	login := lsxd.NewLogin(configConfig, rdb)
	components := component.NewComponents(redisManager, login)
	repos = repo.NewRepos(sessionImpl, configConfig, rdb)
	botToolsImpl := impl.NewBotToolsImpl(db)
	toolRegis := tools_regis.NewToolsRegis(botToolsImpl)
	utils_ossClient, _ := utils_oss.NewClient(configConfig)
	client, _, _ := utils_ollama.NewClient(configConfig)

	registry := workflow.NewRegistry(configConfig, client, repos, components)
	botGroupConfigImpl := impl.NewBotGroupConfigImpl(db)
	botConfigImpl := impl.NewBotConfigImpl(db)
	qywxAppBiz = NewQywxAppBiz(configConfig, botGroupQywxImpl, group, other)
	reportDailyCacheImpl := impl.NewReportDailyCacheImpl(db)
	toolManager := tools.NewManager(configConfig, client)
	oauth2Client, _ := dingtalk.NewOauth2Client(rdb)
	dingtalkCardClient, _ := dingtalk.NewCardClient(oauth2Client)
	groupConfigBiz = NewGroupConfigBiz(toolRegis, utils_ossClient, botGroupConfigImpl, botConfigImpl, registry, configConfig, reportDailyCacheImpl, rdb, toolManager, dingtalkCardClient)
}
