package jobdef

type Registry struct {
	items map[string]Handler
}

func NewRegistry(handlers ...Handler) *Registry {
	items := make(map[string]Handler, len(handlers))
	for _, handler := range handlers {
		items[handler.Key()] = handler
	}

	return &Registry{items: items}
}

func (r *Registry) Get(key string) (Handler, bool) {
	handler, ok := r.items[key]
	return handler, ok
}

func (r *Registry) List() []Handler {
	result := make([]Handler, 0, len(r.items))
	for _, handler := range r.items {
		result = append(result, handler)
	}

	return result
}
