package sales_agents

import (
	"jaecoo-be/app/module/sales_agents/controller"
	"jaecoo-be/app/module/sales_agents/repository"
	"jaecoo-be/app/module/sales_agents/service"

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

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

// NewSalesAgentsModule register bulky of SalesAgents module
var NewSalesAgentsModule = fx.Options(
	// register repository of SalesAgents module
	fx.Provide(repository.NewSalesAgentsRepository),

	// register service of SalesAgents module
	fx.Provide(service.NewSalesAgentsService),

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

	// register router of SalesAgents module
	fx.Provide(NewSalesAgentsRouter),
)

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

// RegisterSalesAgentsRoutes register routes of SalesAgents module
func (_i *SalesAgentsRouter) RegisterSalesAgentsRoutes() {
	// define controllers
	salesAgentsController := _i.Controller.SalesAgents

	// define routes
	_i.App.Route("/sales-agents", func(router fiber.Router) {
		router.Get("/", salesAgentsController.All)
		router.Get("/viewer/:filename", salesAgentsController.Viewer)
		router.Get("/:id", salesAgentsController.Show)
		router.Post("/", salesAgentsController.Save)
		router.Put("/:id", salesAgentsController.Update)
		router.Delete("/:id", salesAgentsController.Delete)
	})
}

