package campaigns

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

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

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

// NewCampaignsModule register bulky of Campaigns module
var NewCampaignsModule = fx.Options(
	// register repository of Campaigns module
	fx.Provide(repository.NewCampaignsRepository),

	// register service of Campaigns module
	fx.Provide(service.NewCampaignsService),

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

	// register router of Campaigns module
	fx.Provide(NewCampaignsRouter),
)

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

// RegisterCampaignsRoutes register routes of Campaigns module
func (_i *CampaignsRouter) RegisterCampaignsRoutes() {
	// define controllers
	campaignsController := _i.Controller.Campaigns

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

