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

type WeeklySignInConfigRow struct {
	ID     int          // #周签到
	Reward []ItemReward // 奖励
}

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

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

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

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

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

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