package mongoLogger

import (
	"fmt"
	"os"

	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func InitLogger() (*zap.Logger, error) {
	mongoCore, err := NewMongoCore(
		"mongodb://root:secret@mongo:27017/?authSource=admin",
		"logdb",
		"applogs",
		zapcore.InfoLevel,
	)
	if err != nil {
		return nil, fmt.Errorf("failed to create MongoDB core: %w", err)
	}

	consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())
	consoleCore := zapcore.NewCore(consoleEncoder, zapcore.Lock(os.Stdout), zapcore.DebugLevel)

	combinedCore := zapcore.NewTee(mongoCore, consoleCore)

	logger := zap.New(combinedCore, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel))

	return logger, nil
}
