package activityCfg

import (
	"server/GoUtil"
	"server/gamedata"
	"server/pkg/github.com/name5566/leaf/log"
	"strconv"
)

const (
	CFG_ACTIVITY = "Activity"
)

func init() {
	gamedata.InitCfg(CFG_ACTIVITY)
}

func GetActivityList() []*gamedata.ActivityData {
	data, err := gamedata.GetData(CFG_ACTIVITY)
	if err != nil {
		log.Debug("GetActivityList err:%v", err)
	}
	Now := GoUtil.Now()
	var List []*gamedata.ActivityData

	for k, v := range data {
		StartTimeStr := gamedata.GetStringValue(v, "StartTime")
		EndTimeStr := gamedata.GetStringValue(v, "EndTime")
		StartTime := GoUtil.ParseTime(StartTimeStr)
		EndTime := GoUtil.ParseTime(EndTimeStr)
		if Now >= StartTime && Now <= EndTime {
			Id, _ := strconv.Atoi(k)
			Type := gamedata.GetIntValue(v, "Type")
			Name := gamedata.GetStringValue(v, "Name")
			Title := gamedata.GetStringValue(v, "Title")
			Level := gamedata.GetIntValue(v, "Level")
			ActivityData := &gamedata.ActivityData{
				Id:        Id,
				Type:      Type,
				Name:      Name,
				Title:     Title,
				Level:     Level,
				StartTime: StartTime,
				EndTime:   EndTime,
			}
			List = append(List, ActivityData)
		}
	}
	return List
}
