package router

import (
	"hyapp-admin-server/internal/config"
	"hyapp-admin-server/internal/middleware"
	"hyapp-admin-server/internal/modules/achievementconfig"
	"hyapp-admin-server/internal/modules/adminuser"
	"hyapp-admin-server/internal/modules/appconfig"
	"hyapp-admin-server/internal/modules/appregistry"
	"hyapp-admin-server/internal/modules/appuser"
	"hyapp-admin-server/internal/modules/audit"
	authroutes "hyapp-admin-server/internal/modules/auth"
	"hyapp-admin-server/internal/modules/coinledger"
	"hyapp-admin-server/internal/modules/countryregion"
	"hyapp-admin-server/internal/modules/cprelation"
	"hyapp-admin-server/internal/modules/cumulativerechargereward"
	"hyapp-admin-server/internal/modules/dailytask"
	"hyapp-admin-server/internal/modules/dashboard"
	"hyapp-admin-server/internal/modules/firstrechargereward"
	gamemanagement "hyapp-admin-server/internal/modules/gamemanagement"
	"hyapp-admin-server/internal/modules/giftdiamond"
	"hyapp-admin-server/internal/modules/health"
	"hyapp-admin-server/internal/modules/hostagencypolicy"
	"hyapp-admin-server/internal/modules/hostorg"
	"hyapp-admin-server/internal/modules/hostsalarysettlement"
	"hyapp-admin-server/internal/modules/inviteactivityreward"
	"hyapp-admin-server/internal/modules/job"
	"hyapp-admin-server/internal/modules/levelconfig"
	"hyapp-admin-server/internal/modules/luckygift"
	"hyapp-admin-server/internal/modules/menu"
	"hyapp-admin-server/internal/modules/payment"
	"hyapp-admin-server/internal/modules/prettyid"
	"hyapp-admin-server/internal/modules/rbac"
	"hyapp-admin-server/internal/modules/redpacket"
	"hyapp-admin-server/internal/modules/regionblock"
	"hyapp-admin-server/internal/modules/registrationreward"
	reportmodule "hyapp-admin-server/internal/modules/report"
	resourcemodule "hyapp-admin-server/internal/modules/resource"
	"hyapp-admin-server/internal/modules/roomadmin"
	"hyapp-admin-server/internal/modules/roomrocket"
	"hyapp-admin-server/internal/modules/roomturnoverreward"
	"hyapp-admin-server/internal/modules/search"
	"hyapp-admin-server/internal/modules/sevendaycheckin"
	"hyapp-admin-server/internal/modules/teamsalarypolicy"
	"hyapp-admin-server/internal/modules/teamsalarysettlement"
	"hyapp-admin-server/internal/modules/upload"
	"hyapp-admin-server/internal/modules/userleaderboard"
	"hyapp-admin-server/internal/modules/vipconfig"
	"hyapp-admin-server/internal/modules/weeklystar"
	"hyapp-admin-server/internal/platform/logging"
	"hyapp-admin-server/internal/service"

	"github.com/gin-gonic/gin"
)

type Handlers struct {
	AdminUser            *adminuser.Handler
	AchievementConfig    *achievementconfig.Handler
	AppConfig            *appconfig.Handler
	AppRegistry          *appregistry.Handler
	AppUser              *appuser.Handler
	Audit                *audit.Handler
	Auth                 *authroutes.Handler
	CoinLedger           *coinledger.Handler
	CountryRegion        *countryregion.Handler
	CPRelation           *cprelation.Handler
	CumulativeRecharge   *cumulativerechargereward.Handler
	DailyTask            *dailytask.Handler
	Dashboard            *dashboard.Handler
	FirstRechargeReward  *firstrechargereward.Handler
	Game                 *gamemanagement.Handler
	GiftDiamond          *giftdiamond.Handler
	Health               *health.Handler
	HostAgencyPolicy     *hostagencypolicy.Handler
	HostOrg              *hostorg.Handler
	HostSalarySettlement *hostsalarysettlement.Handler
	InviteActivityReward *inviteactivityreward.Handler
	Job                  *job.Handler
	LevelConfig          *levelconfig.Handler
	LuckyGift            *luckygift.Handler
	Menu                 *menu.Handler
	Payment              *payment.Handler
	PrettyID             *prettyid.Handler
	RBAC                 *rbac.Handler
	RedPacket            *redpacket.Handler
	Report               *reportmodule.Handler
	RegistrationReward   *registrationreward.Handler
	RegionBlock          *regionblock.Handler
	Resource             *resourcemodule.Handler
	RoomAdmin            *roomadmin.Handler
	RoomRocket           *roomrocket.Handler
	RoomTurnoverReward   *roomturnoverreward.Handler
	Search               *search.Handler
	SevenDayCheckIn      *sevendaycheckin.Handler
	TeamSalaryPolicy     *teamsalarypolicy.Handler
	TeamSalarySettlement *teamsalarysettlement.Handler
	Upload               *upload.Handler
	UserLeaderboard      *userleaderboard.Handler
	VIPConfig            *vipconfig.Handler
	WeeklyStar           *weeklystar.Handler
}

func New(cfg config.Config, auth *service.AuthService, h Handlers) *gin.Engine {
	engine := gin.New()
	engine.Use(middleware.RequestID(), middleware.AppCode(), logging.GinAccessLogger(), gin.Recovery(), middleware.CORS(cfg))

	engine.GET("/healthz", h.Health.Health)
	engine.GET("/readyz", h.Health.Ready)

	api := engine.Group("/api/v1")
	protected := api.Group("")
	protected.Use(middleware.AuthRequired(auth), middleware.Audit(h.Audit))

	authroutes.RegisterRoutes(api, protected, h.Auth)
	achievementconfig.RegisterRoutes(protected, h.AchievementConfig)
	coinledger.RegisterRoutes(protected, h.CoinLedger)
	menu.RegisterRoutes(protected, h.Menu)
	rbac.RegisterRoutes(protected, h.RBAC)
	redpacket.RegisterRoutes(protected, h.RedPacket)
	reportmodule.RegisterRoutes(protected, h.Report)
	resourcemodule.RegisterRoutes(protected, h.Resource)
	adminuser.RegisterRoutes(protected, h.AdminUser)
	appuser.RegisterRoutes(protected, h.AppUser)
	appregistry.RegisterRoutes(protected, h.AppRegistry)
	appconfig.RegisterRoutes(protected, h.AppConfig)
	countryregion.RegisterRoutes(protected, h.CountryRegion)
	cprelation.RegisterRoutes(protected, h.CPRelation)
	cumulativerechargereward.RegisterRoutes(protected, h.CumulativeRecharge)
	dailytask.RegisterRoutes(protected, h.DailyTask)
	firstrechargereward.RegisterRoutes(protected, h.FirstRechargeReward)
	registrationreward.RegisterRoutes(protected, h.RegistrationReward)
	regionblock.RegisterRoutes(protected, h.RegionBlock)
	gamemanagement.RegisterRoutes(protected, h.Game)
	giftdiamond.RegisterRoutes(protected, h.GiftDiamond)
	roomadmin.RegisterRoutes(protected, h.RoomAdmin)
	roomrocket.RegisterRoutes(protected, h.RoomRocket)
	roomturnoverreward.RegisterRoutes(protected, h.RoomTurnoverReward)
	dashboard.RegisterRoutes(protected, h.Dashboard)
	hostagencypolicy.RegisterRoutes(protected, h.HostAgencyPolicy)
	hostsalarysettlement.RegisterRoutes(protected, h.HostSalarySettlement)
	hostorg.RegisterRoutes(protected, h.HostOrg)
	inviteactivityreward.RegisterRoutes(protected, h.InviteActivityReward)
	audit.RegisterRoutes(protected, h.Audit)
	payment.RegisterRoutes(protected, h.Payment)
	prettyid.RegisterRoutes(protected, h.PrettyID)
	job.RegisterRoutes(protected, h.Job)
	levelconfig.RegisterRoutes(protected, h.LevelConfig)
	luckygift.RegisterRoutes(protected, h.LuckyGift)
	upload.RegisterRoutes(protected, h.Upload)
	search.RegisterRoutes(protected, h.Search)
	sevendaycheckin.RegisterRoutes(protected, h.SevenDayCheckIn)
	teamsalarypolicy.RegisterRoutes(protected, h.TeamSalaryPolicy)
	teamsalarysettlement.RegisterRoutes(protected, h.TeamSalarySettlement)
	userleaderboard.RegisterRoutes(protected, h.UserLeaderboard)
	vipconfig.RegisterRoutes(protected, h.VIPConfig)
	weeklystar.RegisterRoutes(protected, h.WeeklyStar)

	return engine
}
