package custom_static_pages

import (
	"narasi-ahli-be/app/module/custom_static_pages/controller"
	"narasi-ahli-be/app/module/custom_static_pages/repository"
	"narasi-ahli-be/app/module/custom_static_pages/service"

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

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

// register bulky of CustomStaticPages module
var NewCustomStaticPagesModule = fx.Options(
	// register repository of CustomStaticPages module
	fx.Provide(repository.NewCustomStaticPagesRepository),

	// register service of CustomStaticPages module
	fx.Provide(service.NewCustomStaticPagesService),

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

	// register router of CustomStaticPages module
	fx.Provide(NewCustomStaticPagesRouter),
)

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

// register routes of CustomStaticPages module
func (_i *CustomStaticPagesRouter) RegisterCustomStaticPagesRoutes() {
	// define controllers
	customStaticPagesController := _i.Controller.CustomStaticPages

	// define routes
	_i.App.Route("/custom-static-pages", func(router fiber.Router) {
		router.Get("/", customStaticPagesController.All)
		router.Get("/:id", customStaticPagesController.Show)
		router.Get("/slug/:slug", customStaticPagesController.ShowBySlug)
		router.Post("/", customStaticPagesController.Save)
		router.Put("/:id", customStaticPagesController.Update)
		router.Delete("/:id", customStaticPagesController.Delete)
	})
}
