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

type DrawConfigRow struct {
	ID                   int          // #规则ID
	Type                 int          // 规则类型(1新手2基础)
	Order                int          //排序
	Reward               []ItemReward //奖励
	Weight               int          // 权重
	HourTotalCondition   int          // 每小时最多中奖次数条件
	DailyTotalCondition  int          // 每天最多中奖次数
	WeeklyTotalCondition int          // 每周最多中奖次数
	PersonTotalCondition int          // 个人最多中奖次数条件
}

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

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

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

func (p *drawConfig) GetMap() map[int]*DrawConfigRow {
	return p.maps
}

func (p *drawConfig) GetByType(tp int) map[int]*DrawConfigRow {
	var result = make(map[int]*DrawConfigRow)
	for k, row := range p.maps {
		if row.Type == tp {
			result[k] = row
		}
	}
	return result
}

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

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