// 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 rocketLvConfig struct {
	maps map[int]*RocketLvConfigRow
}

type RocketLvConfigRow struct {
	ID     int // #进度条等级
	LvNeed int // 升级下级所需人数 最大等级1000级配置为-1
}

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

func (p *rocketLvConfig) Init() {
	p.maps = make(map[int]*RocketLvConfigRow)
}

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

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

		loadMaps[loadConfig.ID] = loadConfig
	}

	p.maps = loadMaps

	return len(list), nil
}

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

func (p *rocketLvConfig) Get(pk int) (*RocketLvConfigRow, bool) {
	i, found := p.maps[pk]
	return i, found
}

func (p *rocketLvConfig) GetAll() map[int]*RocketLvConfigRow {
	var ret = make(map[int]*RocketLvConfigRow)
	for _, v := range p.maps {
		ret[v.ID] = v
	}
	return ret
}

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