package approval_histories

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

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

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

// register bulky of ApprovalHistories module
var NewApprovalHistoriesModule = fx.Options(
	// register repository of ApprovalHistories module
	fx.Provide(repository.NewApprovalHistoriesRepository),

	// register service of ApprovalHistories module
	fx.Provide(service.NewApprovalHistoriesService),

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

	// register router of ApprovalHistories module
	fx.Provide(NewApprovalHistoriesRouter),
)

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

// register routes of ApprovalHistories module
func (_i *ApprovalHistoriesRouter) RegisterApprovalHistoriesRoutes() {
	// define controllers
	approvalHistoriesController := _i.Controller.ApprovalHistories

	// define routes
	_i.App.Route("/approval-histories", func(router fiber.Router) {
		router.Get("/", approvalHistoriesController.All)
		router.Get("/:module_type/:module_id", approvalHistoriesController.GetByModule)
	})
}

