package users

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

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

func GetUsers(c *fiber.Ctx) error {
	// swagger:operation GET /users users usersGetUsers
	// ---
	// summary: Get all users
	// 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: All users
	//     schema:
	//       "$ref": "#/definitions/UsersResponse"
	//   '401':
	//     description: No permissions
	//   '500':
	//     description: Failed to get users

	var user structs.User

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

	return c.JSON(structs.UsersResponse{
		RoleId: user.RoleId,
		Users:  socketclients.GetAllUsers(),
		Roles:  socketclients.GetAllRoles(),
	})
}
