package logger

import (
	"log"

	"go.uber.org/zap"

	"git.kanopo.dev/rhythm/rhythm-backend/internal/config"
)

func New(env string) (*zap.Logger, *zap.SugaredLogger) {
	var zapLogger *zap.Logger
	var err error

	if env == "production" {
		zapLogger, err = zap.NewProduction()
	} else {
		zapLogger, err = zap.NewDevelopment()
	}

	if err != nil {
		log.Fatalf("failed to initialize zap logger: %v", err)
	}

	return zapLogger, zapLogger.Sugar()
}

func ProvideLogger(cfg *config.Config) (*zap.Logger, *zap.SugaredLogger) {
	return New(cfg.AppEnv)
}

type GooseLogger struct {
	*zap.SugaredLogger
}

func (l *GooseLogger) Fatal(v ...interface{}) {
	l.SugaredLogger.Fatal(v...)
}

func (l *GooseLogger) Fatalf(format string, v ...interface{}) {
	l.SugaredLogger.Fatalf(format, v...)
}

func (l *GooseLogger) Print(v ...interface{}) {
	l.SugaredLogger.Info(v...)
}

func (l *GooseLogger) Printf(format string, v ...interface{}) {
	l.SugaredLogger.Infof(format, v...)
}
