package notification

import (
	// External
	werr "git.gibonuddevalla.se/go/wrappederror"

	// Standard
	"log/slog"
)

func ServiceFactory(t string, config []byte, prio int, ackURL string, logger *slog.Logger) (Service, error) {
	switch t {
	case "NTFY":
		ntfy, err := NewNTFY(config, prio, ackURL)
		if err != nil {
			err = werr.Wrap(err).WithData(config)
			return nil, err
		}
		ntfy.SetLogger(logger)
		return ntfy, nil
	case "SCRIPT":
		script, err := NewScript(config, prio, ackURL)
		if err != nil {
			err = werr.Wrap(err).WithData(config)
			return nil, err
		}
		script.SetLogger(logger)
		return script, nil
	}

	return nil, werr.New("Unknown notification service, '%s'", t).WithCode("002-0000")
}
