package controller

import (
	"github.com/gin-gonic/gin"
	"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 {
		ctx.JSON(200, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}
	resp, total, err := w.sev.List(ctx, req)
	if err != nil {
		ctx.JSON(200, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}
	ctx.JSON(200, gin.H{
		"code":  200,
		"data":  resp,
		"msg":   "success",
		"total": total,
	})
}

func (w *PlayerManage) GetPlayerInfo(ctx *gin.Context) {
	req := entity.PlayerInfoReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		ctx.JSON(200, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}
	resp, err := w.sev.PlayerInfo(ctx, req)
	if err != nil {
		ctx.JSON(200, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}
	ctx.JSON(200, gin.H{
		"code": 200,
		"data": resp,
		"msg":  "success",
	})
}

func (w *PlayerManage) GetRewardList(ctx *gin.Context) {
	req := entity.RewardListReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		ctx.JSON(200, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}
	resp, total, err := w.sev.RewardList(ctx, req)
	if err != nil {
		ctx.JSON(200, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}
	ctx.JSON(200, gin.H{
		"code":  200,
		"data":  resp,
		"msg":   "success",
		"total": total,
	})
}
