package model

import (
	"time"

	"mongo.games.com/goserver/core/logger"
)

type RankSeasonId struct {
	//Id       bson.ObjectId `bson:"_id"`
	Platform string
	SeasonId int32 //赛季id
	StartTs  int64 //开始时间戳
	EndTs    int64 //结束时间戳
	UpdateTs int64 //更新时间戳
}

type RankSeasonIdRet struct {
	MsId *RankSeasonId
}

type RankSeasonIdByKey struct {
	Platform string
}

func UpsertRankSeasonId(RankSeasonId *RankSeasonId) bool {
	if rpcCli == nil {
		logger.Logger.Error("model.UpsertRankSeasonId rpcCli == nil")
		return false
	}

	var ret bool
	RankSeasonId.UpdateTs = time.Now().Unix()
	err := rpcCli.CallWithTimeout("RankSeasonIdSvc.Upsert", RankSeasonId, &ret, time.Second*30)
	if err != nil {
		logger.Logger.Error("model.UpsertRankSeasonId error:", err)
		return false
	}
	return ret
}

func FindOneRankSeasonId(platform string) (RankSeasonId *RankSeasonId, err error) {
	if rpcCli == nil {
		logger.Logger.Error("model.FindOneRankSeasonId rpcCli == nil")
		return
	}
	args := &RankSeasonIdByKey{
		Platform: platform,
	}
	var ret *RankSeasonIdRet
	err = rpcCli.CallWithTimeout("RankSeasonIdSvc.FindOne", args, &ret, time.Second*30)
	if err != nil {
		logger.Logger.Error("model.FindOneRankSeasonId error:", err)
	}
	if ret != nil {
		RankSeasonId = ret.MsId
	}
	return
}
