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

type InviteConfigRow struct {
	ID        int          // #id
	Reward    []ItemReward // 奖励
	Condition int          // 邀请好友数量所需数量
}

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

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

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

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

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

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