package player

import (
	mhayaTime "github.com/mhaya/extend/time"
	"github.com/mhaya/game/game_cluster/internal/constant"
	"github.com/mhaya/game/game_cluster/internal/data"
	"github.com/mhaya/game/game_cluster/internal/mdb/models"
)

// loginStat 登录相关
func (p *actorPlayer) loginStat() {
	if mhayaTime.CreateFromTimestamp(p.Account.JoinTime).IsToday() {
		models.SetDailyRecordUserHash(p.Account.Platform, p.Account.Channel, p.Player.UserName, models.DailyRecordNewLogin)
	} else {
		models.SetDailyRecordUserHash(p.Account.Platform, p.Account.Channel, p.Player.UserName, models.DailyRecordOldLogin)
	}
}

// RollStat 投筛子相关
func (p *actorPlayer) rollStat() {
	if mhayaTime.CreateFromTimestamp(p.Account.JoinTime).IsToday() {
		models.SetDailyRecordUserHash(p.Account.Platform, p.Account.Channel, p.Player.UserName, models.DailyRecordNewActive)
	} else {
		models.SetDailyRecordUserHash(p.Account.Platform, p.Account.Channel, p.Player.UserName, models.DailyRecordOldActive)
	}
}

func (p *actorPlayer) itemStat(item map[int]*data.ItemReward) {
	for _, v := range item {
		if v.ItemID == models.ItemScore {
			models.SetRank(constant.RankSourceScore, p.Player.IsRobot, p.Player.UserName, v.Amount)
			models.SetDailyRecord(p.Account.Platform, p.Account.Channel, models.DailyRecordTotalPoints, v.Amount)
		} else if v.ItemID == models.ItemU {
			models.SetDailyRecord(p.Account.Platform, p.Account.Channel, models.DailyRecordUProduced, v.Amount)
		}
	}
}

func (p *actorPlayer) cashOutStat(num int) {
	models.SetDailyRecord(p.Account.Platform, p.Account.Channel, models.DailyRecordUCashout, num)
}

func (p *actorPlayer) playerStart() {
	models.SetTotalPlayerRecord(p.Account.Platform, p.Account.Channel, p.Player.UserName, p.Player.Level)
}
