package users

import (
	"context"
	"net/http"

	"fr.latosa-escrima/core"
	"fr.latosa-escrima/core/models"
)

func HandleRoles(w http.ResponseWriter, r *http.Request) {
	user_id := r.PathValue("user_uuid")
	var user models.User
	err := core.DB.NewSelect().Model(&user).Where("user_id = ?", user_id).
		Relation("Roles").
		Limit(1).
		Scan(context.Background())
	if err != nil {
		core.JSONError{
			Status:  core.Error,
			Message: err.Error(),
		}.Respond(w, http.StatusInternalServerError)
		return
	}

	core.JSONSuccess{
		Status:  core.Success,
		Message: "Roles found.",
		Data:    user.Roles,
	}.Respond(w, http.StatusOK)
}
