package middleware

import (
	"github.com/juju/errors"
	"github.com/ngaut/log"
	"github.com/pingcap/schrodinger/notifiermgr/event"
	"github.com/pingcap/schrodinger/notifiermgr/util"
)

func getUndestroyedAbnormalUnalertedExperimentsDriver(configPtr *interface{}) Middleware {
	input := make(chan event.Event)
	output := make(chan event.Event)

	store, err := util.GetStorageFromConfig(configPtr)
	if err != nil {
		log.Errorf("Error while connecting storage: %s", errors.ErrorStack(err))
	}

	go func() {
		for range input {
			exps := store.ListUnAlertedExperiments()

			output <- exps
		}
	}()

	return &RealMiddleware{
		input,
		output,
	}
}
