package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/mhaya/game/game_cluster/internal/code"
	"github.com/mhaya/game/game_cluster/nodes/webadmin/common"
	"github.com/mhaya/game/game_cluster/nodes/webadmin/entity"
	"github.com/mhaya/game/game_cluster/nodes/webadmin/service"
)

type PlayerManage struct {
	sev *service.PlayerManage
}

func NewPlayerManage() *PlayerManage {
	return &PlayerManage{
		sev: service.NewPlayerManage(),
	}
}

// 获取玩家列表
func (w *PlayerManage) GetPlayerlist(ctx *gin.Context) {
	req := entity.PlayerListReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		common.PackOkResult(ctx, code.ParamError)
		return
	}
	resp, err := w.sev.List(ctx, req)
	if err != nil {
		common.PackOkResult(ctx, err.Code)
		return
	}

	common.PackOkResult(ctx, code.OK, resp)
}

// 获取玩家详情
func (w *PlayerManage) GetPlayerInfo(ctx *gin.Context) {
	req := entity.PlayerInfoReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		common.PackOkResult(ctx, code.ParamError)
		return
	}

	resp, err := w.sev.PlayerInfo(ctx, req)
	if err != nil {
		common.PackOkResult(ctx, err.Code)
		return
	}

	common.PackOkResult(ctx, code.OK, resp)
}

// 获取玩家中奖记录(默认查询最近三天)
func (w *PlayerManage) GetRewardList(ctx *gin.Context) {
	req := entity.RewardListReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		common.PackOkResult(ctx, code.ParamError)
		return
	}

	resp, err := w.sev.RewardList(ctx, req)
	if err != nil {
		common.PackOkResult(ctx, err.Code)
		return
	}

	common.PackOkResult(ctx, code.OK, resp)
}
