package adminkindboxreqhandler

import (
	"net/http"

	param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
	httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
	"github.com/labstack/echo/v4"
)

// Get godoc
// @Summary      Get a specific kind box req by ID
// @Tags         Admins KindBoxReqs
// @Accept       json
// @Produce      json
// @Param        id path int true "KindBoxReq ID"
// @Success      200  {object}  param.GetKindBoxReqResponse
// @Failure      400  {string}  "Bad Request"
// @Failure      401  {string}  "invalid or expired jwt"
// @Failure      403  {string}  "user not allowed"
// @Failure      422  {object}  httpmsg.ErrorResponse
// @Failure      500  {string}  "something went wrong"
// @Security 	 AuthBearerAdmin
// @Router       /admins/kindboxreqs/{id} [get].
func (h Handler) Get(c echo.Context) error {
	var req param.GetKindBoxReqRequest
	if err := c.Bind(&req); err != nil {
		return echo.NewHTTPError(http.StatusBadRequest)
	}

	resp, err := h.adminKindBoxReqSvc.Get(c.Request().Context(), req)
	if err != nil {
		msg, code := httpmsg.Error(err)
		if resp.FieldErrors != nil {
			return c.JSON(code, echo.Map{
				"message": msg,
				"errors":  resp.FieldErrors,
			})
		}

		return echo.NewHTTPError(code, msg)
	}

	return c.JSON(http.StatusOK, resp)
}