package app

import (
	"bindbox-game/internal/pkg/logger"
	"bindbox-game/internal/repository/mysql"
	"bindbox-game/internal/repository/mysql/dao"
	activitysvc "bindbox-game/internal/service/activity"
	tasksvc "bindbox-game/internal/service/task_center"
	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
	activity      activitysvc.Service
	title         titlesvc.Service
	repo          mysql.Repo
	user          usersvc.Service
	task          tasksvc.Service
	redis         *redis.Client
	activityOrder activitysvc.ActivityOrderService // 活动订单服务
}

func New(logger logger.CustomLogger, db mysql.Repo, rdb *redis.Client, task tasksvc.Service) *handler {
	userSvc := usersvc.New(logger, db)
	return &handler{
		logger:        logger,
		writeDB:       dao.Use(db.GetDbW()),
		readDB:        dao.Use(db.GetDbR()),
		activity:      activitysvc.New(logger, db, userSvc, rdb),
		title:         titlesvc.New(logger, db),
		repo:          db,
		user:          userSvc,
		task:          task,
		redis:         rdb,
		activityOrder: activitysvc.NewActivityOrderService(logger, db),
	}
}
