package magazines

import (
	"github.com/gofiber/fiber/v2"
	"go.uber.org/fx"
	"web-qudo-be/app/module/magazines/controller"
	"web-qudo-be/app/module/magazines/repository"
	"web-qudo-be/app/module/magazines/service"
)

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

// register bulky of Magazines module
var NewMagazinesModule = fx.Options(
	// register repository of Magazines module
	fx.Provide(repository.NewMagazinesRepository),

	// register service of Magazines module
	fx.Provide(service.NewMagazinesService),

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

	// register router of Magazines module
	fx.Provide(NewMagazinesRouter),
)

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

// register routes of Magazines module
func (_i *MagazinesRouter) RegisterMagazinesRoutes() {
	// define controllers
	magazinesController := _i.Controller.Magazines

	// define routes
	_i.App.Route("/magazines", func(router fiber.Router) {
		router.Get("/", magazinesController.All)
		router.Get("/:id", magazinesController.Show)
		router.Post("/", magazinesController.Save)
		router.Put("/:id", magazinesController.Update)
		router.Post("/thumbnail/:id", magazinesController.SaveThumbnail)
		router.Get("/thumbnail/viewer/:thumbnailName", magazinesController.Viewer)
		router.Delete("/:id", magazinesController.Delete)
	})
}
