package public

import (
	"git.ma-al.com/goc_daniel/b2b/app/service/menuService"
	"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
	"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
	"git.ma-al.com/goc_daniel/b2b/app/utils/response"
	"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
	"github.com/gofiber/fiber/v3"
)

type RoutingHandler struct {
	menuService *menuService.MenuService
}

func NewRoutingHandler() *RoutingHandler {
	menuService := menuService.New()
	return &RoutingHandler{
		menuService: menuService,
	}
}

// AuthHandlerRoutes registers all auth routes
func RoutingHandlerRoutes(r fiber.Router) fiber.Router {
	handler := NewRoutingHandler()

	r.Get("/get-routes", handler.GetRouting)

	return r
}

func (h *RoutingHandler) GetRouting(c fiber.Ctx) error {
	lang_id, ok := c.Locals("langID").(uint)
	if !ok {
		return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
			JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
	}
	menu, err := h.menuService.GetRoutes(lang_id)
	if err != nil {
		return c.Status(responseErrors.GetErrorStatus(err)).
			JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
	}

	return c.JSON(response.Make(&menu, 0, i18n.T_(c, response.Message_OK)))
}
