package router

import (
	"github.com/gin-gonic/gin"
	mhayaGin "github.com/mhaya/components/gin"
	cfacade "github.com/mhaya/facade"
	"github.com/mhaya/game/game_cluster/nodes/webadmin/controller"
)

type Controller struct {
	mhayaGin.BaseController
}

func (c *Controller) Init() {
	c.SetRouter()
}

// CreateUserController 创建用户的控制
func (c *Controller) CreateUserController() {
	// parentActor := &user.User{}
	// c.CreateActor(parentActor.AliasID(), parentActor)
}

func (c *Controller) CreateActor(id string, handler cfacade.IActorHandler) {
	// system := bcwinActor.NewSystem()
	// system.SetApp(c.App)
	// system.CreateActor(id, handler)
}

// SetRouter 设置路由
func (c *Controller) SetRouter() {
	u := c.Group("/v1")
	uu := u.Group("/admin")
	login := uu.Group("/user/login")
	login.Use(loginRecordMiddleware(c.App))
	login.POST("", controller.NewAdmin().Login)

	c.InitApiRouter(uu)
}

func (c *Controller) InitApiRouter(u *gin.RouterGroup) {
	u.Use(Auth(c.App))

	nodeId := c.App.NodeId()

	// 综合统计
	u.POST("/statistics/overview", controller.NewSynthesis(nodeId).Overview)

	// 活动统计 目前没有活动模块
	u.POST("/statistics/activity", controller.NewSynthesis(nodeId).Activity)

	// 用户统计
	u.POST("/statistics/user/list", controller.NewSynthesis(nodeId).UserList)
	u.POST("/user/log/daily", controller.NewSynthesis(nodeId).FindUserLogDaily)

	// 玩家相关信息
	u.POST("/player/list", controller.NewPlayerManage().GetPlayerlist)
	u.POST("/player/info", controller.NewPlayerManage().GetPlayerInfo)
	u.POST("/player/rewardList", controller.NewPlayerManage().GetRewardList)

	// 转盘统计
	u.POST("/statistics/turntable", controller.NewSynthesis(nodeId).Turntable)

	// 资产统计
	u.POST("/statistics/assets", controller.NewSynthesis(nodeId).Assets)
	u.POST("/statistics/assetsRecord", controller.NewSynthesis(nodeId).AssetsRecord)

	// 邀请统计
	u.POST("/statistics/invite", controller.NewSynthesis(nodeId).Invite)

	// 任务完成度统计
	u.POST("/statistics/taskCompletion", controller.NewSynthesis(nodeId).TaskCompletion)

	// 用户行为检测
	u.POST("/user/behaviorMonitoring", controller.NewSynthesis(nodeId).BehaviorMonitoring)

	// 后台操作记录
	u.POST("/user/log", controller.NewSynthesis(nodeId).Records)

	// 活跃统计
	u.POST("/statistics/active", controller.NewSynthesis(nodeId).Active)
	u.POST("/user/retention", controller.NewSynthesis(nodeId).FindUserRetention)
	u.POST("/user/country", controller.NewSynthesis(nodeId).FindUserCountryCount)
	u.POST("/user/level", controller.NewSynthesis(nodeId).FindUserLevel)

	// 提现统计
	u.POST("/user/withdrawal", controller.NewSynthesis(nodeId).FindWithdrawal)
	u.POST("/user/withdrawal/export", controller.NewSynthesis(nodeId).WithdrawalExport)
	u.POST("/user/withdrawal/status", controller.NewSynthesis(nodeId).WithdrawalStatus)
	u.POST("/user/withdrawal/status_batch", controller.NewSynthesis(nodeId).WithdrawalStatusBatch)

	// 账号管理
	u.POST("/user/changePassword", controller.NewAdmin().ChangePassword)
	u.POST("/user/add", controller.NewAdmin().Add)
	u.POST("/user/del", controller.NewAdmin().Del)
	u.POST("/user/find", controller.NewAdmin().FindAll)
	u.POST("/user/update", controller.NewAdmin().UpdateStatus)
	u.POST("/user/serverStatus", controller.NewAdmin().GetServerStatus)

	// 账号角色管理
	u.POST("/role/add", controller.NewRole().Add)
	u.POST("/role/update", controller.NewRole().Update)
	u.POST("/role/del", controller.NewRole().Del)
	u.POST("/role/list", controller.NewRole().List)
	u.POST("/role/access/add", controller.NewRole().AddAccess)
	u.POST("/role/access/del", controller.NewRole().DelAccess)
	u.POST("/role/access/list", controller.NewRole().ListAccess)
	u.POST("/role/access/update", controller.NewRole().UpdateAccess)
	u.POST("/role/role_access/add", controller.NewRole().AddRoleAccess)
	u.POST("/role/role_access/del", controller.NewRole().DelRoleAccess)
	u.POST("/role/role_access/list", controller.NewRole().GetRoleAccessList)
	u.POST("/role/role_access/update", controller.NewRole().UpdateRoleAccess)
	u.POST("/role/admin_unbind_role", controller.NewRole().AdminUnBindRole)
	u.POST("/role/admin_bind_role", controller.NewRole().AdminBindRole)
	u.POST("/role/admin_role_info", controller.NewRole().GetAdminRole)

	// IP白名单
	u.POST("/whitelist/add", controller.NewWhitelist().AddWhitelist)
	u.POST("/whitelist/remove", controller.NewWhitelist().RemoveWhitelist)
	u.POST("/whitelist/list", controller.NewWhitelist().GetWhitelist)

	// 风控
	u.POST("/riskControl/multipleFingerprintInIp", controller.NewRiskControl().MultipleFingerprintInIp)
	u.POST("/riskControl/multipleAddressInTg", controller.NewRiskControl().MultipleAddressInTg)
	u.POST("/riskControl/multipleTgInAddress", controller.NewRiskControl().MultipleTgInAddress)
	u.POST("/riskControl/multipleTgInIp", controller.NewRiskControl().MultipleTgInIp)
}

// func (c *Controller) InitMdb() {
// 	MdbAdmin, _ = mdb.InitializeMongoDB()
// }
