package event

import "qteam/app/utils"

type EventHandler interface {
	Handle(param interface{})
}

type EventManagerFactory struct {
	handers map[string][]EventHandler
}

func (this *EventManagerFactory) Register(eventName string, handler EventHandler) {
	if this.handers == nil {
		this.handers = make(map[string][]EventHandler)
	}
	this.handers[eventName] = append(this.handers[eventName], handler)

}

func (this *EventManagerFactory) TrigerEvent(eventName string, param interface{}) {
	defer func() {
		err := recover()
		if err != nil {
			utils.Log(nil, "event err", err)
		}

	}()

	for _, v := range this.handers[eventName] {
		v.Handle(param)
	}

}
