package clients

import (
	"netidhub-saas-be/app/module/clients/controller"
	"netidhub-saas-be/app/module/clients/repository"
	"netidhub-saas-be/app/module/clients/service"

	"github.com/gofiber/fiber/v2"
	"go.uber.org/fx"
)

// struct of ClientsRouter
type ClientsRouter struct {
	App        fiber.Router
	Controller *controller.Controller
}

// register bulky of Clients module
var NewClientsModule = fx.Options(
	// register repository of Clients module
	fx.Provide(repository.NewClientsRepository),

	// register client logo upload service
	fx.Provide(service.NewClientLogoUploadService),

	// register service of Clients module
	fx.Provide(service.NewClientsService),

	// register controller of Clients module
	fx.Provide(controller.NewController),

	// register router of Clients module
	fx.Provide(NewClientsRouter),
)

// init ClientsRouter
func NewClientsRouter(fiber *fiber.App, controller *controller.Controller) *ClientsRouter {
	return &ClientsRouter{
		App:        fiber,
		Controller: controller,
	}
}

// register routes of Clients module
func (_i *ClientsRouter) RegisterClientsRoutes() {
	// define controllers
	clientsController := _i.Controller.Clients

	// define routes
	_i.App.Route("/clients", func(router fiber.Router) {
		router.Get("/", clientsController.All)
		router.Get("/:id", clientsController.Show)
		router.Get("/profile", clientsController.ShowWithAuth)
		router.Post("/", clientsController.Save)
		router.Post("/with-user", clientsController.CreateClientWithUser)
		router.Put("/:id", clientsController.Update)
		router.Put("/update", clientsController.UpdateWithAuth)
		router.Delete("/:id", clientsController.Delete)

		// Logo upload routes
		router.Post("/logo", clientsController.UploadLogo)
		router.Delete("/:id/logo", clientsController.DeleteLogo)
		router.Get("/:id/logo/url", clientsController.GetLogoURL)
	})
}
