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

type PlatformConfigRow struct {
	ID     int    // 平台ID
	Name   string // 名称
	Enable int    //是否开启
}

func (p *platformConfig) Name() string {
	return "PlatformConfig"
}

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

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

func (p *platformConfig) GatMap() map[int]*PlatformConfigRow {
	var ret = make(map[int]*PlatformConfigRow)
	for _, v := range p.maps {
		if v.Enable == 1 {
			ret[v.ID] = v
		}
	}
	return ret
}

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

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