package advertisement

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

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

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

// register bulky of Advertisement module
var NewAdvertisementModule = fx.Options(
	// register repository of Advertisement module
	fx.Provide(repository.NewAdvertisementRepository),

	// register service of Advertisement module
	fx.Provide(service.NewAdvertisementService),

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

	// register router of Advertisement module
	fx.Provide(NewAdvertisementRouter),
)

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

// register routes of Advertisement module
func (_i *AdvertisementRouter) RegisterAdvertisementRoutes() {
	// define controllers
	advertisementController := _i.Controller.Advertisement

	// define routes
	_i.App.Route("/advertisement", func(router fiber.Router) {
		router.Get("/", advertisementController.All)
		router.Get("/:id", advertisementController.Show)
		router.Post("/", advertisementController.Save)
		router.Post("/upload/:id", advertisementController.Upload)
		router.Get("/viewer/:filename", advertisementController.Viewer)
		router.Put("/:id", advertisementController.Update)
		router.Put("/publish/:id", advertisementController.UpdatePublish)
		router.Delete("/:id", advertisementController.Delete)
	})
}
