package clients

import (
	"github.com/nats-io/nats.go"
	"github.com/rs/zerolog/log"
	"github.com/spf13/viper"
)

var natsConn *nats.Conn

// InitNATSClient initializes the NATS client connection.
func InitNATSClient() {
	natsURL := viper.GetString("nats.url")
	if natsURL == "" {
		log.Fatal().Msg("NATS URL not configured in viper (nats.url)")
	}

	var err error
	natsConn, err = nats.Connect(natsURL)
	if err != nil {
		log.Fatal().Err(err).Msg("Failed to connect to NATS server")
	}
	log.Info().Msgf("Connected to NATS server: %s", natsURL)
}

// GetNATSClient returns the initialized NATS client connection.
func GetNATSClient() *nats.Conn {
	return natsConn
}
