package team

import (
	"database/sql"
	"log"
	"net/http"
	"volleyball/internal/common"

	"github.com/gin-gonic/gin"
)

func GetTeams(c *gin.Context, db *sql.DB) {
	log.Println(c.GetString("userId"), c.GetString("email"), c.GetString("role"))
	// Simulate fetching players from a database

	teams, err := GetAllTeams(db)
	if err != nil {
		log.Printf("Error retrieving teams: %v", err)
		common.RespondError(c, http.StatusInternalServerError, "Failed to retrieve players")
		return
	}

	if len(teams) > 0 {
		log.Printf("User %s (%s) requested players", c.GetString("userId"), c.GetString("email"))
		c.JSON(http.StatusOK, teams)
		return
	}
	log.Printf("User %s (%s) requested players, but none found", c.GetString("userId"), c.GetString("email"))

	common.RespondError(c, http.StatusNotFound, "No Players found")
}
