package utils

import (
	"context"
	"io"

	"golang.org/x/exp/slog"
)

type loggerWriter struct {
	logger   *slog.Logger
	logLevel slog.Level
}

func (lw *loggerWriter) Write(p []byte) (n int, err error) {
	lw.logger.Log(context.Background(), lw.logLevel, string(p))
	return len(p), nil
}

func LoggerWriter(logger *slog.Logger, level slog.Level) io.Writer {
	return &loggerWriter{logger: logger, logLevel: level}
}
