// Package logging provides structured logging configuration for
// Switchboard Core using the standard library's log/slog package.
// Configured via LOG_FORMAT ("text"|"json") and LOG_LEVEL env vars.
package logging

import (
	"log/slog"
	"os"
	"strings"
)

// Init configures the global slog logger.
//
//   - format: "json" for machine-parseable output, anything else for
//     human-readable key=value pairs (backward-compatible default).
//   - level: "debug", "info" (default), "warn", "error".
func Init(format, level string) {
	var lvl slog.Level
	switch strings.ToLower(level) {
	case "debug":
		lvl = slog.LevelDebug
	case "warn", "warning":
		lvl = slog.LevelWarn
	case "error":
		lvl = slog.LevelError
	default:
		lvl = slog.LevelInfo
	}

	opts := &slog.HandlerOptions{Level: lvl}
	var handler slog.Handler
	if strings.ToLower(format) == "json" {
		handler = slog.NewJSONHandler(os.Stdout, opts)
	} else {
		handler = slog.NewTextHandler(os.Stdout, opts)
	}

	slog.SetDefault(slog.New(handler))
}
