package article_files

import (
	"campaign-pool-be/app/module/article_files/controller"
	"campaign-pool-be/app/module/article_files/repository"
	"campaign-pool-be/app/module/article_files/service"

	"github.com/gofiber/fiber/v2"
	"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),
	fx.Provide(service.NewUploadService),
	fx.Provide(service.NewUploadManager),

	// 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/:filename", articleFilesController.Viewer)
		router.Get("/upload-status/:uploadId", articleFilesController.GetUploadStatus)
	})
}
