package cms_content_submissions

import (
	"web-qudo-be/app/middleware"
	"web-qudo-be/app/module/cms_content_submissions/controller"
	"web-qudo-be/app/module/cms_content_submissions/repository"
	"web-qudo-be/app/module/cms_content_submissions/service"
	usersRepo "web-qudo-be/app/module/users/repository"

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

type CmsContentSubmissionsRouter struct {
	App        fiber.Router
	Controller *controller.Controller
	UsersRepo  usersRepo.UsersRepository
}

var NewCmsContentSubmissionsModule = fx.Options(
	fx.Provide(repository.NewCmsContentSubmissionsRepository),
	fx.Provide(service.NewCmsContentSubmissionsService),
	fx.Provide(controller.NewController),
	fx.Provide(NewCmsContentSubmissionsRouter),
)

func NewCmsContentSubmissionsRouter(
	fiber *fiber.App,
	ctrl *controller.Controller,
	usersRepo usersRepo.UsersRepository,
) *CmsContentSubmissionsRouter {
	return &CmsContentSubmissionsRouter{
		App:        fiber,
		Controller: ctrl,
		UsersRepo:  usersRepo,
	}
}

func (_i *CmsContentSubmissionsRouter) RegisterCmsContentSubmissionsRoutes() {
	h := _i.Controller.CmsContentSubmissions
	_i.App.Route("/cms-content-submissions", func(router fiber.Router) {
		router.Use(middleware.UserMiddleware(_i.UsersRepo))
		router.Post("/", h.Submit)
		router.Get("/", h.List)
		router.Post("/:id/approve", h.Approve)
		router.Post("/:id/reject", h.Reject)
	})
}
