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

type SdkConfigRow struct {
	ID           int      // #sdkID
	CallbackName string   // sdk名称
	Salt         string   // 盐
	Params       SdkParam // sdk配置信息
	S3           S3Param  //s3配置表
	Desc         string   // 描述信息
}

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

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

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

func (p *sdkConfig) Get(pk int) *SdkConfigRow {
	i, _ := p.maps[pk]
	return i
}

func (p *sdkConfig) GetWithName(callName string) *SdkConfigRow {
	if callName == "" {
		return nil
	}

	for _, row := range p.maps {
		if row.CallbackName == callName {
			return row
		}
	}

	return nil
}
