package app

import (
	"bindbox-game/internal/pkg/logger"
	"bindbox-game/internal/repository/mysql"
	"bindbox-game/internal/repository/mysql/dao"
	"bindbox-game/internal/service/douyin"
	gamesvc "bindbox-game/internal/service/game"
	"bindbox-game/internal/service/sysconfig"
	tasksvc "bindbox-game/internal/service/task_center"
	titlesvc "bindbox-game/internal/service/title"
	usersvc "bindbox-game/internal/service/user"
)

type handler struct {
	logger  logger.CustomLogger
	writeDB *dao.Query
	readDB  *dao.Query
	user    usersvc.Service
	task    tasksvc.Service
	douyin  douyin.Service
	repo    mysql.Repo
}

func New(logger logger.CustomLogger, db mysql.Repo, taskSvc tasksvc.Service) *handler {
	syscfgSvc := sysconfig.New(logger, db)
	userSvc := usersvc.New(logger, db)
	titleSvc := titlesvc.New(logger, db)
	return &handler{
		logger:  logger,
		writeDB: dao.Use(db.GetDbW()),
		readDB:  dao.Use(db.GetDbR()),
		user:    userSvc,
		task:    taskSvc,
		douyin:  douyin.New(logger, db, syscfgSvc, gamesvc.NewTicketService(logger, db), userSvc, titleSvc),
		repo:    db,
	}
}
