package model

import (
	"github.com/globalsign/mgo/bson"
	"mongo.games.com/goserver/core/logger"
	"time"
)

var (
	BurstJackpotLogDBName        = "log"
	BurstJackpotLogCollName      = "log_burstjackpotlog"
	TopicProbeBurstJackpotLogAck = "ack_burstjackpotlog"
)

type BurstJackpotLog struct {
	LogId      bson.ObjectId `bson:"_id"`
	Platform   string
	GameId     int32
	GameFreeId int32
	Name       string //用户昵称
	WinCoin    int64  //爆奖金额
	TotalBet   int64  //下注
	Ts         int64  //创建时间
}

func NewBurstJackpotLog(platform string, gameId, gameFreeId int32, name string, winCoin, totalBet int64) *BurstJackpotLog {
	log := &BurstJackpotLog{
		LogId:      bson.NewObjectId(),
		Platform:   platform,
		GameId:     gameId,
		GameFreeId: gameFreeId,
		Name:       name,
		WinCoin:    winCoin,
		TotalBet:   totalBet,
		Ts:         time.Now().Unix(),
	}
	return log
}

type BurstJackpotArg struct {
	Platform string
	GameId   int32
	Logs     []BurstJackpotLog
}

func GetBurstJackpotLog(platform string, gameId int32) []BurstJackpotLog {
	if rpcCli == nil {
		logger.Logger.Error("GetBurstJackpotLog RPClient no connect")
		return nil
	}
	args := &BurstJackpotArg{
		Platform: platform,
		GameId:   gameId,
	}
	var ret []BurstJackpotLog
	err := rpcCli.CallWithTimeout("BurstJackpotSvc.GetBurstJackpotLog", args, &ret, time.Second*30)
	if err != nil {
		logger.Logger.Error("model.GetBurstJackpotLog error", err)
		return nil
	}
	return ret
}
func InsertBurstJackpotLogs(logs *BurstJackpotLog) error {
	if rpcCli == nil {
		return ErrRPClientNoConn
	}
	var ret bool
	err := rpcCli.CallWithTimeout("BurstJackpotSvc.InsertBurstJackpotLogs", logs, &ret, time.Second*30)
	if err != nil {
		logger.Logger.Error("model.InsertBurstJackpotLogs error", err)
		return err
	}
	return err
}
