package model

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

	"xorm.io/xorm"
)

// 补给特权 2项
type SupplyPrivilege2 struct {
	FreeDay   int64 `json:"freeDay"`   // 免费已签到天数
	SeniorDay int64 `json:"seniorDay"` // 高级已签到天数
	IsSenior  int64 `json:"isSenior"`  // 是否购买高级基金 0:未购买，1:已购买
}

type Gift struct {
	BuyNum    map[int64]int64 `json:"buynum"`
	LastBuyTs int64           `json:"lastbuytime"`
}

// 玩家寻宝数据
type HuntTreasurePlayer struct {
	Id            int64             // id
	PlayerId      int64             `xorm:"BIGINT index 'playerid'"` // 玩家ID
	HuntCount     int64             `xorm:"int 'huntcount'"`         // 寻宝次数
	ProcessReward int64             `xorm:"int 'processreward'"`     // 已领取进度奖励
	LuckNum       int64             `xorm:"int 'lucknum'"`           // 幸运值
	LastFreeTs    int64             `xorm:"BIGINT 'lastfreetime'"`   // 最后一次免费寻宝时间
	Supply        *SupplyPrivilege2 `xorm:"TEXT json 'supply'"`      // 补给
	Exchanges     map[int64]int64   `xorm:"TEXT json 'exchanges'"`   // 兑换记录
	Gift          *Gift             `xorm:"TEXT json 'gift'"`        // 礼包

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

// TableName 表名
func (m *HuntTreasurePlayer) TableName() string {
	return "player_hunttreasure"
}

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

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

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

func CopyHuntTreasurePlayer(old *HuntTreasurePlayer) *HuntTreasurePlayer {
	nu := deepcopy.MustCopy(old).(*HuntTreasurePlayer)
	return nu
}
