package logger

import (
	"github.com/AlchemyTelcoSolutions/xutils-go/xlogger"
	"go.uber.org/zap"
)

type Logger struct {
	logger      xlogger.Logger
	contextTags []zap.Field
}

func New(xlogger xlogger.Logger) *Logger {
	return &Logger{logger: xlogger}
}

// AddContextTag append a new tag to keep during thowl context
func (l *Logger) AddContextTag(key, value string) *Logger {
	tag := zap.String(key, value)
	l.contextTags = append(l.contextTags, tag)
	return l
}

// Print
func (l *Logger) Print(v ...interface{}) {
	l.logger.Print(v...)
}

// Printf
func (l *Logger) Printf(format string, v ...interface{}) {
	l.logger.Printf(format, v...)
}

// Debug
func (l *Logger) Debug(msg string, tags ...zap.Field) {
	tags = append(tags, l.contextTags...)
	l.logger.Debug(msg, tags...)
}

// Info
func (l *Logger) Info(msg string, tags ...zap.Field) {
	tags = append(tags, l.contextTags...)
	l.logger.Info(msg, tags...)
}

// Warning
func (l *Logger) Warning(msg string, tags ...zap.Field) {
	tags = append(tags, l.contextTags...)
	l.logger.Warning(msg, tags...)
}

// Error
func (l *Logger) Error(msg string, err error, tags ...zap.Field) {
	tags = append(tags, l.contextTags...)
	l.logger.Error(msg, err, tags...)
}

// Panic
func (l *Logger) Panic(msg string, err error, tags ...zap.Field) {
	tags = append(tags, l.contextTags...)
	l.logger.Panic(msg, err, tags...)
}

// Fatal
func (l *Logger) Fatal(msg string, err error, tags ...zap.Field) {
	tags = append(tags, l.contextTags...)
	l.logger.Fatal(msg, err, tags...)
}

// With returns the logger with appended fields
func (l *Logger) With(fields ...zap.Field) *zap.Logger {
	return l.logger.With(append(fields, l.contextTags...)...)
}

// ZapLogger returns the underlying zap logger
func (l *Logger) ZapLogger() *zap.Logger {
	return l.logger.ZapLogger()
}
