package promotions

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

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

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

// NewPromotionsModule register bulky of Promotions module
var NewPromotionsModule = fx.Options(
	// register repository of Promotions module
	fx.Provide(repository.NewPromotionsRepository),

	// register service of Promotions module
	fx.Provide(service.NewPromotionsService),

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

	// register router of Promotions module
	fx.Provide(NewPromotionsRouter),
)

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

// RegisterPromotionsRoutes register routes of Promotions module
func (_i *PromotionsRouter) RegisterPromotionsRoutes() {
	// define controllers
	promotionsController := _i.Controller.Promotions

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

