package clients

import (
	"web-qudo-be/app/module/clients/controller"
	"web-qudo-be/app/module/clients/repository"
	"web-qudo-be/app/module/clients/service"

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


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

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

	// 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.Post("/", clientsController.Save)
		router.Put("/:id", clientsController.Update)
		router.Delete("/:id", clientsController.Delete)
	})
}
