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

type LevelConfigRow struct {
	ID        int // #level
	DiceNum   int // 投骰子数量
	Invite    int // 邀请好友数量
	Ratio     int // 倍率
	DiceLimit int // 额外骰子上限
	Rule1     int // 规则1按大小
	Rule2     int // 规则2按对子
	Rule3     int // 规则3其他豹子
	Rule4     int // 规则4豹子111/666
}

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

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

func (p *levelConfig) 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]*LevelConfigRow)
	for index, data := range list {
		loadConfig := &LevelConfigRow{}
		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 *levelConfig) OnAfterLoad(_ bool) {
}

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

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

func (p *levelConfig) GetMap() map[int]*LevelConfigRow {
	return p.maps
}
