package product_specifications

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

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

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

// NewProductSpecificationsModule register bulky of ProductSpecifications module
var NewProductSpecificationsModule = fx.Options(
	// register repository of ProductSpecifications module
	fx.Provide(repository.NewProductSpecificationsRepository),

	// register service of ProductSpecifications module
	fx.Provide(service.NewProductSpecificationsService),

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

	// register router of ProductSpecifications module
	fx.Provide(NewProductSpecificationsRouter),
)

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

// RegisterProductSpecificationsRoutes register routes of ProductSpecifications module
func (_i *ProductSpecificationsRouter) RegisterProductSpecificationsRoutes() {
	// define controllers
	productSpecificationsController := _i.Controller.ProductSpecifications

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

