package admin

import (
	"bindbox-game/internal/pkg/logger"
	"bindbox-game/internal/repository/mysql"
	"bindbox-game/internal/repository/mysql/dao"
	activitysvc "bindbox-game/internal/service/activity"
	adminsvc "bindbox-game/internal/service/admin"
	bannersvc "bindbox-game/internal/service/banner"
	channelsvc "bindbox-game/internal/service/channel"
	douyinsvc "bindbox-game/internal/service/douyin"
	productsvc "bindbox-game/internal/service/product"
	snapshotsvc "bindbox-game/internal/service/snapshot"
	syscfgsvc "bindbox-game/internal/service/sysconfig"
	titlesvc "bindbox-game/internal/service/title"
	usersvc "bindbox-game/internal/service/user"

	"github.com/redis/go-redis/v9"
)

type handler struct {
	logger      logger.CustomLogger
	writeDB     *dao.Query
	readDB      *dao.Query
	repo        mysql.Repo
	svc         adminsvc.Service
	activity    activitysvc.Service
	product     productsvc.Service
	userSvc     usersvc.Service
	banner      bannersvc.Service
	channel     channelsvc.Service
	title       titlesvc.Service
	syscfg      syscfgsvc.Service
	snapshotSvc snapshotsvc.Service
	rollbackSvc snapshotsvc.RollbackService
	douyinSvc   douyinsvc.Service
}

func New(logger logger.CustomLogger, db mysql.Repo, rdb *redis.Client) *handler {
	userSvc := usersvc.New(logger, db)
	snapshotSvc := snapshotsvc.NewService(db)
	rollbackSvc := snapshotsvc.NewRollbackService(db, snapshotSvc)
	syscfgSvc := syscfgsvc.New(logger, db)
	return &handler{
		logger:      logger,
		writeDB:     dao.Use(db.GetDbW()),
		readDB:      dao.Use(db.GetDbR()),
		repo:        db,
		svc:         adminsvc.New(logger, db),
		activity:    activitysvc.New(logger, db, userSvc, rdb),
		product:     productsvc.New(logger, db),
		userSvc:     userSvc,
		banner:      bannersvc.New(logger, db),
		channel:     channelsvc.New(logger, db),
		title:       titlesvc.New(logger, db),
		syscfg:      syscfgSvc,
		snapshotSvc: snapshotSvc,
		rollbackSvc: rollbackSvc,
		douyinSvc:   douyinsvc.New(logger, db, syscfgSvc, nil),
	}
}
