package player

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

func (p *actorPlayer) share(req *param.ShareReq) (*param.ChangeData, int32) {
	//if !p.isOnline {
	//	return nil, code.PlayerNotLogin
	//}
	var resp param.ChangeData
	switch req.Tp {
	case 1:
		if p.Player.Share.IsDrawShare == 0 {
			ret, ok := data.DiscreteRuleConfig.Get(models.ShareLottery)
			if !ok {
				return nil, code.OK
			}
			p.Player.Share.IsDrawShare = 1
			p.Player.Share.DrawShareTime = mhayaTime.Now().Unix()
			p.Player.Item.AddItem(ret.Reward)
			var addItem models.AddItem
			resp.AddItem = addItem.Add(ret.Reward)
			p.Player.SetPlayerRewardLog(models.SourceShare, 1, ret.Reward, []data.ItemReward{}, nil)
			p.dirty = true

			p.itemStat(resp.AddItem)
		}
	}

	return &resp, code.OK
}
