package svc

import (
	"github.com/globalsign/mgo"
	"mongo.games.com/game/dbproxy/mongo"
	"mongo.games.com/game/model"
	"mongo.games.com/goserver/core/logger"
	"net/rpc"
)

func DbVipLogCollection(plt string) *mongo.Collection {
	s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, model.DbVipDBName)
	if s != nil {
		dbVipRec, first := s.DB().C(model.DbVipCollName)
		if first {
			dbVipRec.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true})
			dbVipRec.EnsureIndex(mgo.Index{Key: []string{"type"}, Background: true, Sparse: true})
		}
		return dbVipRec
	}
	return nil
}

type DbVipLogSvc struct {
}

func (svc *DbVipLogSvc) InsertDbVipLog(args *model.DbVipLogArgs, ret *bool) (err error) {
	clog := DbVipLogCollection(args.Log.Platform)
	if clog == nil {
		return
	}
	logger.Logger.Trace("DbVipLogSvc.InsertDbVipLog")
	err = clog.Insert(args.Log)
	if err != nil {
		logger.Logger.Error("DbVipLogSvc.InsertDbVipLog error:", err)
		return
	}
	*ret = true
	return
}
func init() {
	rpc.Register(new(DbVipLogSvc))
}
