package gameServerMgr

import (
	. "Framework/managecenterModel"
)

var (
	mPartnerMap = make(map[int32]*Partner, 0)
)

//解析合作商信息
func ParsePartnerInfo(partnerList []*Partner) {
	tmpPartnerMap := make(map[int32]*Partner, 0)

	//循环解析所有合作商信息
	for _, partner := range partnerList {
		tmpPartnerMap[partner.Id] = partner
	}

	mPartnerMap = tmpPartnerMap
}

//根据渠道id获取渠道对象
func GetPartnerItem(partnerId int32) (partner *Partner, exist bool) {

	//判断渠道是否存在
	partner, exist = mPartnerMap[partnerId]

	return
}

//获取渠道的登录加密key
func GetLoginKey(partnerId int32) (loginKey string, exist bool) {
	partnerObj, exist := mPartnerMap[partnerId]
	if !exist {
		return
	}

	loginKey = partnerObj.LoginKey

	return
}

//根据渠道和key获取其他配置
func GetOtherConfigInfo(partnerId int32, configKey string) (configValue string, exist bool, err error) {
	partnerObj, exist := GetPartnerItem(partnerId)
	if !exist {
		return
	}

	var otherConfigMap map[string]string
	otherConfigMap, err = partnerObj.ResolveOtherConfig()
	if err != nil {
		return
	}

	configValue, exist = otherConfigMap[configKey]

	return
}
