package v1

import (
	"github.com/labstack/echo"
	"net/http"
	"strconv"
	"git.mowie.cc/konrad/Library/models"
)

func UserShow(c echo.Context) error {
	user := c.Param("id")

	if user == "" {
		return c.JSON(http.StatusBadRequest, models.Message{"User ID cannot be empty."})
	}

	// Make int
	userID, err := strconv.ParseInt(user, 10, 64)
	if err != nil {
		return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
	}

	// Get User Infos
	userInfos, exists, err := models.GetUserByID(userID)

	if err != nil {
		return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
	}

	// Check if it exists
	if !exists {
		return c.JSON(http.StatusNotFound, models.Message{"User not found."})
	}

	return c.JSON(http.StatusOK, userInfos)
}