package master_modules

import (
	"campaign-pool-be/app/module/master_modules/controller"
	"campaign-pool-be/app/module/master_modules/repository"
	"campaign-pool-be/app/module/master_modules/service"

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

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

// register bulky of MasterModules module
var NewMasterModulesModule = fx.Options(
	// register repository of MasterModules module
	fx.Provide(repository.NewMasterModulesRepository),

	// register service of MasterModules module
	fx.Provide(service.NewMasterModulesService),

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

	// register router of MasterModules module
	fx.Provide(NewMasterModulesRouter),
)

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

// register routes of MasterModules module
func (_i *MasterModulesRouter) RegisterMasterModulesRoutes() {
	// define controllers
	masterModulesController := _i.Controller.MasterModules

	// define routes
	_i.App.Route("/master-modules", func(router fiber.Router) {
		router.Get("/", masterModulesController.All)
		router.Get("/:id", masterModulesController.Show)
		router.Post("/", masterModulesController.Save)
		router.Put("/:id", masterModulesController.Update)
		router.Delete("/:id", masterModulesController.Delete)
	})
}
