package staffhttp

import (
	staffsvc "legalgo-BE-go/internal/services/staff"
	"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,
	authSvc staffsvc.Auth,
) {
	router.Get("/staff/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
		}

		staffProfile, err := authSvc.GetProfile(destructedToken.ID)
		if err != nil {
			response.ResponseWithErrorCode(
				ctx,
				w,
				err,
				response.ErrBadRequest.Code,
				response.ErrBadRequest.HttpCode,
				err.Error(),
			)
			return
		}

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