package handler

import (
	"encoding/json"
	"fmt"
	"net/http"
	"sirlab.de/go/knowyt/user"
)

type UserInfoJson struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Role    string `json:"role"`
	GameId  string `json:"game"`
	IsCameo string `json:"isCameo",omitempty`
}

func (authMux *AuthMux) GetUserInfo(usr *user.User, w http.ResponseWriter, r *http.Request) {
	usrLight := UserInfoJson{
		Id:     usr.GetId(),
		Name:   usr.GetName(),
		Role:   usr.GetRole(),
		GameId: usr.GetGameId(),
	}
	if usr.GetCameo() != nil {
		usrLight.IsCameo = "true"
	}

	w.Header().Add("Content-Type", "application/json")
	jsonString, _ := json.Marshal(usrLight)
	fmt.Fprintf(w, string(jsonString))
}