package model

import (
	"encoding/json"
	"mongo.games.com/goserver/core/logger"
	"os"
)

var (
	ThirdPltGameMappingConfig = ThirdPlatformGameMappingConfiguration{}
)

var GameMappingPath = "../data/DB_ThirdPlatformGameMapping.json"

type ThirdPlatformGameMappingConfiguration struct {
	Arr []mappingItem
}
type mappingItem struct {
	SystemGameID      int32
	ThirdPlatformName string
	ThirdGameID       string
	Desc              string
}

func InitGameMappingConfig() {
	buf, err := os.ReadFile(GameMappingPath)
	if err != nil {
		logger.Logger.Error("InitGameMappingConfig os.ReadFile error ->", err)
	}

	err = json.Unmarshal(buf, &ThirdPltGameMappingConfig)
	if err != nil {
		logger.Logger.Error("InitGameMappingConfig json.Unmarshal error ->", err)
		return
	}
}

func (this *ThirdPlatformGameMappingConfiguration) FindByGameID(systemGameID int32) (ok bool, item *mappingItem) {
	for k, v := range this.Arr {
		if v.SystemGameID == systemGameID {
			return true, &this.Arr[k]
		}
	}
	return false, nil
}
