package service

import (
	"blazing/cool"
	"blazing/modules/blazing/model"
)

// TalkCheck 获取玩家当前的Talk数据
// todo 待实现xml解析判断是否溢出
func (s *UserService) TalkCheck() map[uint32]uint32 {

	m1 := s.Model(s.talk.Model)

	var talks []model.Talk
	m1.Scan(&talks)

	return talks[0].Data
}

// TalkAdd 添加或更新玩家的Talk数据
func (s *UserService) TalkAdd(id, count uint32) {
	var player model.Talk
	m1 := cool.DBM(s.talk.Model).Where("player_id", s.userid)
	m1.Scan(&player)

	// // 如果玩家没有记录，则初始化
	// if len(talks) == 0 {
	// 	player.PlayerID = uint64(s.userid)
	// 	player.Data = "{}"
	// 	_, err := m1.Insert(player)
	// 	if err != nil {
	// 		panic(err)
	// 	}
	// }

	// // 更新或新增
	// if existing, ok := talks[id]; ok {

	// 	talks[id] = existing + count
	// } else {
	// 	talks[id] = count
	// }

	// data, _ := json.Marshal(talks)
	// player.Data = string(data)
	// m1.Update(player)
}
