package main

import (
	"net/http"
	"server/hall/history"
	"server/msg"

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

func GetHistorList(c *gin.Context) {
	req := c.MustGet("protobuf_data").(*msg.ReqLudoHistory)
	list, err := history.GetHistoryByUserID(req.UserId)
	if err != nil {
		c.ProtoBuf(http.StatusOK, &msg.ResLudoHistory{

			Success: false,
			ErrMsg: &msg.MsgError{
				ErrorCode: 101,
				ErrorMsg:  "GetHistorList is error！",
			},
		})
		return
	}

	c.ProtoBuf(http.StatusOK, &msg.ResLudoHistory{

		Success: true,
		ErrMsg:  nil,
		List:    list,
	})
}

func GetLudoRoomInfo(c *gin.Context) {
	req := c.MustGet("protobuf_data").(*msg.ReqLudoRoomInfo)
	info, err := history.GetRoomInfoByID(int(req.RoomId))
	if err != nil {
		c.ProtoBuf(http.StatusOK, &msg.ResLudoRoomInfo{

			Success: false,
			ErrMsg: &msg.MsgError{
				ErrorCode: 101,
				ErrorMsg:  "GetLudoRoomInfo is error！",
			},
		})
		return
	}

	c.ProtoBuf(http.StatusOK, &msg.ResLudoRoomInfo{

		Success: true,
		ErrMsg:  nil,
		Info:    info,
	})
}
