package log

import (
	"git.links123.net/links123.com/pkg/log/hooks"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

var logger = logrus.New()

func NewDefaultLogger(project *hooks.Project) error {
	return NewLogger(project, hooks.DefaultMaintainers(), hooks.DefaultNotificationService())
}

func NewLogger(project *hooks.Project, maintainers []*hooks.Maintainer, ns *hooks.NotificationService) error {
	notificationHook, err := hooks.NewNotificationHook(project, maintainers, ns)
	if err != nil {
		return err
	}

	logger.AddHook(notificationHook)

	switch gin.Mode() {
	case gin.DebugMode, gin.TestMode:
		logger.SetLevel(logrus.DebugLevel)
	case gin.ReleaseMode:
		logger.SetLevel(logrus.InfoLevel)
	default:
		panic("unsupported running mode")
	}

	return nil
}
