package article_categories

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

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

// register bulky of ArticleCategories module
var NewArticleCategoriesModule = fx.Options(
	// register repository of ArticleCategories module
	fx.Provide(repository.NewArticleCategoriesRepository),

	// register service of ArticleCategories module
	fx.Provide(service.NewArticleCategoriesService),

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

	// register router of ArticleCategories module
	fx.Provide(NewArticleCategoriesRouter),
)

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

// register routes of ArticleCategories module
func (_i *ArticleCategoriesRouter) RegisterArticleCategoriesRoutes() {
	// define controllers
	articleCategoriesController := _i.Controller.ArticleCategories

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