package article_files

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

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

// register bulky of ArticleFiles module
var NewArticleFilesModule = fx.Options(
	// register repository of ArticleFiles module
	fx.Provide(repository.NewArticleFilesRepository),

	// register service of ArticleFiles module
	fx.Provide(service.NewArticleFilesService),

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

	// register router of ArticleFiles module
	fx.Provide(NewArticleFilesRouter),
)

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

// register routes of ArticleFiles module
func (_i *ArticleFilesRouter) RegisterArticleFilesRoutes() {
	// define controllers
	articleFilesController := _i.Controller.ArticleFiles

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