package magazine_files

import (
	"narasi-ahli-be/app/module/magazine_files/controller"
	"narasi-ahli-be/app/module/magazine_files/repository"
	"narasi-ahli-be/app/module/magazine_files/service"

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

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

// register bulky of MagazineFiles module
var NewMagazineFilesModule = fx.Options(
	// register repository of MagazineFiles module
	fx.Provide(repository.NewMagazineFilesRepository),

	// register service of MagazineFiles module
	fx.Provide(service.NewMagazineFilesService),

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

	// register router of MagazineFiles module
	fx.Provide(NewMagazineFilesRouter),
)

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

// register routes of MagazineFiles module
func (_i *MagazineFilesRouter) RegisterMagazineFilesRoutes() {
	// define controllers
	magazineFilesController := _i.Controller.MagazineFiles

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