package router

import (
	"metazone.cc/metalab/internal/config"
	"metazone.cc/metalab/internal/controller"
	adminCtrl "metazone.cc/metalab/internal/controller/admin"
	"metazone.cc/metalab/internal/middleware"
	"metazone.cc/metalab/internal/repository"
	"metazone.cc/metalab/internal/service"

	"gorm.io/gorm"
)

type dependencies struct {
	authCtrl        *controller.AuthController
	authMdw         *middleware.AuthMiddleware
	settingsCtrl    *controller.SettingsController
	messageCtrl     *controller.MessageController
	postCtrl        *controller.PostController
	spaceCtrl       *controller.SpaceController
	studioCtrl      *controller.StudioController
	adminPostCtrl   *adminCtrl.AdminPostController
	adminCtrl       *adminCtrl.AdminController
	auditCtrl       *adminCtrl.AuditController
	siteSettingCtrl *adminCtrl.SiteSettingController
	tokenCtrl       *controller.AuthController
}

func buildDepsCore(db *gorm.DB, cfg *config.Config, siteSettings *config.SiteSettings) (
	*repository.UserRepo, *service.TokenService, *service.AuthService,
	*middleware.RateLimiter, *controller.AuthController,
	*service.AvatarService, *middleware.AuthMiddleware, *adminCtrl.AdminController,
) {
	userRepo := repository.NewUserRepo(db)
	tokenSvc := service.NewTokenService(cfg, userRepo)
	authService := service.NewAuthService(userRepo, tokenSvc, cfg, siteSettings)
	rateLimiter := middleware.NewRateLimiter()
	authCtrl := controller.NewAuthController(authService, tokenSvc, rateLimiter, cfg)
	avatarSvc := service.NewAvatarService(userRepo)
	authMdw := middleware.NewAuthMiddleware(cfg, userRepo)
	adminController := adminCtrl.NewAdminController(service.NewAdminService(userRepo))
	return userRepo, tokenSvc, authService, rateLimiter, authCtrl, avatarSvc, authMdw, adminController
}
