package userhttp

import (
	usersvc "legalgo-BE-go/internal/services/user"
	"legalgo-BE-go/internal/utilities/response"
	"legalgo-BE-go/internal/utilities/utils"
	"net/http"

	"github.com/go-chi/chi/v5"
)

func GetProfile(
	router chi.Router,
	userSvc usersvc.User,
) {
	router.Get("/user/profile", func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		destructedToken, err := utils.GetTokenDetail(r)
		if err != nil {
			response.ResponseWithErrorCode(
				ctx,
				w,
				err,
				response.ErrBadRequest.Code,
				response.ErrBadRequest.HttpCode,
				err.Error(),
			)
			return
		}

		userProfile, err := userSvc.GetUserProfile(destructedToken.ID)
		if err != nil {
			response.ResponseWithErrorCode(
				ctx,
				w,
				err,
				response.ErrBadRequest.Code,
				response.ErrBadRequest.HttpCode,
				err.Error(),
			)
			return
		}

		response.RespondJsonSuccess(ctx, w, userProfile)
	})
}
