package feedbacks

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

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

// register bulky of Feedbacks module
var NewFeedbacksModule = fx.Options(
	// register repository of Feedbacks module
	fx.Provide(repository.NewFeedbacksRepository),

	// register service of Feedbacks module
	fx.Provide(service.NewFeedbacksService),

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

	// register router of Feedbacks module
	fx.Provide(NewFeedbacksRouter),
)

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

// register routes of Feedbacks module
func (_i *FeedbacksRouter) RegisterFeedbacksRoutes() {
	// define controllers
	feedbacksController := _i.Controller.Feedbacks

	// define routes
	_i.App.Route("/feedbacks", func(router fiber.Router) {
		router.Get("/", feedbacksController.All)
		router.Get("/:id", feedbacksController.Show)
		router.Post("/", feedbacksController.Save)
		router.Put("/:id", feedbacksController.Update)
		router.Delete("/:id", feedbacksController.Delete)
		router.Get("/statistic/monthly", feedbacksController.FeedbackMonthlyStats)
	})
}
