{{ define "handlers" }}
{{ $pkg := $.Package }}
{{ template "header" $ }}

{{- range $s := $.Structs }}{{ if eq $s.Interface "UpdateClass" }}
{{ $eventName := trimPrefix $s.Name "Update"}}
// {{ $eventName }}Handler is a {{ $eventName }} event handler.
type {{ $eventName }}Handler func(ctx context.Context, e Entities, update *{{ $s.Name }}) error

// On{{ $eventName }} sets {{ $eventName }} handler.
func (u UpdateDispatcher) On{{ $eventName }}(handler {{ $eventName }}Handler) {
    u.handlers[{{ $s.Name }}TypeID] = func(ctx context.Context, e Entities, update UpdateClass) error {
        return handler(ctx, e, update.(*{{ $s.Name }}))
    }
}
{{- end }}{{ end }}

// OnFallback sets fallback handler.
func (u *UpdateDispatcher) OnFallback(handler Handler) {
    u.fallback = handler
}

{{ end }}
