package subscription

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

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

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

// register bulky of Subscription module
var NewSubscriptionModule = fx.Options(
	// register repository of Subscription module
	fx.Provide(repository.NewSubscriptionRepository),

	// register service of Subscription module
	fx.Provide(service.NewSubscriptionService),

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

	// register router of Subscription module
	fx.Provide(NewSubscriptionRouter),
)

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

// register routes of Subscription module
func (_i *SubscriptionRouter) RegisterSubscriptionRoutes() {
	// define controllers
	subscriptionController := _i.Controller.Subscription

	// define routes
	_i.App.Route("/subscription", func(router fiber.Router) {
		router.Get("/", subscriptionController.All)
		router.Get("/:id", subscriptionController.Show)
		router.Post("/", subscriptionController.Save)
		router.Put("/:id", subscriptionController.Update)
		router.Delete("/:id", subscriptionController.Delete)
	})
}
