package articles

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

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

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

// NewArticlesModule register bulky of Articles module
var NewArticlesModule = fx.Options(
	// register repository of Articles module
	fx.Provide(repository.NewArticlesRepository),

	// register service of Articles module
	fx.Provide(service.NewArticlesService),

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

	// register router of Articles module
	fx.Provide(NewArticlesRouter),
)

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

// RegisterArticlesRoutes register routes of Articles module
func (_i *ArticlesRouter) RegisterArticlesRoutes() {
	// define controllers
	articlesController := _i.Controller.Articles

	// define routes
	_i.App.Route("/articles", func(router fiber.Router) {
		router.Get("/", articlesController.All)
		router.Get("/old-id/:id", articlesController.ShowByOldId)
		router.Get("/:id", articlesController.Show)
		router.Post("/", articlesController.Save)
		router.Put("/:id", articlesController.Update)
		router.Put("/banner/:id", articlesController.UpdateBanner)
		router.Post("/thumbnail/:id", articlesController.SaveThumbnail)
		router.Get("/thumbnail/viewer/:thumbnailName", articlesController.Viewer)
		router.Post("/publish-scheduling", articlesController.PublishScheduling)
		router.Delete("/:id", articlesController.Delete)
		router.Get("/statistic/summary", articlesController.SummaryStats)
		router.Get("/statistic/user-levels", articlesController.ArticlePerUserLevelStats)
		router.Get("/statistic/monthly", articlesController.ArticleMonthlyStats)
	})
}
