package user

import (
	"jannex/admin-dashboard-backend/modules/database"
	"jannex/admin-dashboard-backend/modules/structs"
	"jannex/admin-dashboard-backend/socketclients"

	"github.com/gofiber/fiber/v2"
)

func UserInfo(c *fiber.Ctx) error {
	// swagger:operation GET /user/info user userInfo
	// ---
	// summary: Get user info
	// consumes:
	// - application/json
	// produces:
	// - application/json
	// parameters:
	// - name: X-Api-Key
	//   in: header
	//   description: You can create a new api key in your user profile
	// responses:
	//   '200':
	//     description: User info
	//     schema:
	//       "$ref": "#/definitions/UserInfoResponse"
	//   '401':
	//     description: No permissions
	//   '500':
	//     description: Failed to get user info

	var user structs.User

	database.DB.Select("id, username, avatar", "role_id").First(&user, "id = ?", c.Locals("userId").(string))

	return c.JSON(structs.UserInfoResponse{
		UserId:              user.Id,
		Username:            user.Username,
		Avatar:              user.Avatar,
		Permissions:         socketclients.GetPermissionsByRoleId(user.RoleId),
		AvailableGroupTasks: []string{},
		Users:               socketclients.GetAllUsers(),
	})
}
