package queries

import (
	"backend/db"
	"os"

	"github.com/joho/godotenv"
)

var (
	Db *db.DbHandler
)

func init() {
	_ = godotenv.Load(".env")

	Db = db.NewDbHandler(db.Configs{
		Host:          os.Getenv("PGHOST"),
		Dbname:        os.Getenv("POSTGRES_DB"),
		Port:          os.Getenv("PGPORT"),
		User:          os.Getenv("POSTGRES_USER"),
		Password:      os.Getenv("POSTGRES_PASSWORD"),
		LoggerEnabled: os.Getenv("DB_LOGGER") == "true",
	})

}

func HealthCheck() bool {
	if Db == nil || Db.Dbpool == nil {
		return false
	}
	err := Db.Dbpool.Ping(Db.Ctx)
	return err == nil

}
