package logRecord

import (
	"fmt"
	"game/common/proto/pb"
	rpc "game/common/rpc/logRecord"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/servicex"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type LogRecordApi struct{}

func (e *LogRecordApi) GetUserResLogs(c *gin.Context) {
	var req = &rpc.LogUserResReq{}
	err := c.ShouldBindJSON(req)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if req.UserId < 1 {
		response.FailWithMessage(fmt.Sprintf("玩家id不能为0"), c)
		return
	}

	values, code := rpc.RpcGetUserResLogs(servicex.GetService(), req.UserId, req)
	if code != pb.ErrCode_OK {
		global.GVA_LOG.Error("查询失败!", zap.Error(fmt.Errorf(code.String())))
		response.FailWithMessage("查询失败", c)
		return
	}
	response.OkWithData(gin.H{"log": values}, c)
}
