package model

import (
	"leafstalk/otherutils/deepcopy"
	"strconv"

	"xorm.io/xorm"
)

// 玩家寻宝数据
type GachaPlayer struct {
	Id            int64             // id
	PlayerId      int64             `xorm:"BIGINT index 'playerid'"` // 玩家ID
	GachaCount    int64             `xorm:"int 'gachacount'"`        // 寻宝次数
	ProcessReward int64             `xorm:"int 'processreward'"`     // 已领取进度奖励
	LuckNum       int64             `xorm:"int 'lucknum'"`           // 幸运值
	LastFreeTs    int64             `xorm:"BIGINT 'lastfreetime'"`   // 最后一次免费寻宝时间
	Supply        *SupplyPrivilege2 `xorm:"TEXT json 'supply'"`      // 补给
	Pray          map[int64]int64   `xorm:"TEXT json 'pray'"`        // 祈福记录 {祈福奖励Uid:祈福消耗Uid}
	Gift          *Gift             `xorm:"TEXT json 'gift'"`        // 礼包

	SysLottery *LotteryList `xorm:"-"` // 活动信息
}

// TableName 表名
func (m *GachaPlayer) TableName() string {
	return "player_gacha"
}

func (m *GachaPlayer) QueryExist(eng *xorm.Engine) (bool, error) {
	player := new(GachaPlayer)
	player.PlayerId = m.PlayerId
	return eng.Exist(player)
}

func (m *GachaPlayer) UpdateDB(eng *xorm.Engine) (int64, error) {
	return eng.Where("playerid=?", m.PlayerId).AllCols().Update(m)
}

func (m *GachaPlayer) GetUniqueKey() string {
	return strconv.FormatInt(m.PlayerId, 10)
}

func CopyGachaPlayer(old *GachaPlayer) *GachaPlayer {
	nu := deepcopy.MustCopy(old).(*GachaPlayer)
	return nu
}
