package banners

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

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

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

// NewBannersModule register bulky of Banners module
var NewBannersModule = fx.Options(
	// register repository of Banners module
	fx.Provide(repository.NewBannersRepository),

	// register service of Banners module
	fx.Provide(service.NewBannersService),

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

	// register router of Banners module
	fx.Provide(NewBannersRouter),
)

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

// RegisterBannersRoutes register routes of Banners module
func (_i *BannersRouter) RegisterBannersRoutes() {
	// define controllers
	bannersController := _i.Controller.Banners

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

