package handlers

import (
	"net/http"
	"runtime"
	"time"

	"github.com/gin-gonic/gin"
	"lan-manager/server/db"
)

var startTime = time.Now()

type HealthHandler struct{}

func NewHealthHandler() *HealthHandler {
	return &HealthHandler{}
}

func (h *HealthHandler) Check(c *gin.Context) {
	dbErr := db.DB.Ping()
	status := "ok"
	dbStatus := "ok"
	if dbErr != nil {
		status = "error"
		dbStatus = "error"
	}
	c.JSON(http.StatusOK, gin.H{
		"status":  status,
		"db":      dbStatus,
		"version": "1.0.0",
		"uptime":  time.Since(startTime).String(),
		"go":      runtime.Version(),
	})
}
