// this file is auto create by program, don't edit manually

package data

import (
	mhayaError "github.com/mhaya/error"
	mhayaLogger "github.com/mhaya/logger"
)

type playerConfig struct {
	maps map[int64]*playerConfigRow
}

type playerConfigRow struct {
	OpenId int64 `json:"openId"` // 6543537208
	Level  int   `json:"level"`  // 8
}

func (p *playerConfig) Name() string {
	return "playerConfig"
}

func (p *playerConfig) Init() {
	p.maps = make(map[int64]*playerConfigRow)
}

func (p *playerConfig) OnLoad(maps interface{}, _ bool) (int, error) {
	list, ok := maps.([]interface{})
	if !ok {
		return 0, mhayaError.Error("maps convert to []interface{} error.")
	}

	loadMaps := make(map[int64]*playerConfigRow)
	for index, data := range list {
		loadConfig := &playerConfigRow{}
		err := DecodeData(data, loadConfig)
		if err != nil {
			mhayaLogger.Warnf("decode error. [row = %d, %v], err = %s", index+1, loadConfig, err)
			continue
		}

		loadMaps[loadConfig.OpenId] = loadConfig
	}

	p.maps = loadMaps

	return len(list), nil
}

func (p *playerConfig) OnAfterLoad(_ bool) {
}

func (p *playerConfig) Get(pk int64) (*playerConfigRow, bool) {
	i, found := p.maps[pk]
	return i, found
}

func (p *playerConfig) Contain(pk int64) bool {
	_, found := p.Get(pk)
	return found
}
