package products

import (
	"jaecoo-be/app/module/products/controller"
	"jaecoo-be/app/module/products/repository"
	"jaecoo-be/app/module/products/service"

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

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

// NewProductsModule register bulky of Products module
var NewProductsModule = fx.Options(
	// register repository of Products module
	fx.Provide(repository.NewProductsRepository),

	// register service of Products module
	fx.Provide(service.NewProductsService),

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

	// register router of Products module
	fx.Provide(NewProductsRouter),
)

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

// RegisterProductsRoutes register routes of Products module
func (_i *ProductsRouter) RegisterProductsRoutes() {
	// define controllers
	productsController := _i.Controller.Products

	// define routes
	_i.App.Route("/products", func(router fiber.Router) {
		router.Get("/", productsController.All)
		router.Get("/viewer/:filename", productsController.Viewer)
		router.Get("/:id", productsController.Show)
		router.Post("/", productsController.Save)
		router.Put("/:id", productsController.Update)
		router.Delete("/:id", productsController.Delete)
	})
}

