package web

import (
	"io"
	"log/slog"
)

// NewSlogHandler returns a slog.Handler appropriate for the supplied
// environment. When env == "production" the returned handler emits
// machine-parseable JSON; for any other value (including the empty string
// and "development") the handler emits human-readable text. Both handlers
// are configured at slog.LevelInfo.
//
// The caller is responsible for wiring the returned handler into a
// slog.Logger (typically via slog.SetDefault) — this function is a pure
// helper and intentionally has no side effects.
func NewSlogHandler(env string, w io.Writer) slog.Handler {
	opts := &slog.HandlerOptions{Level: slog.LevelInfo}
	if env == "production" {
		return slog.NewJSONHandler(w, opts)
	}
	return slog.NewTextHandler(w, opts)
}
