package provinces

import (
	"github.com/gofiber/fiber/v2"
	"go-humas-be/app/module/provinces/controller"
	"go-humas-be/app/module/provinces/repository"
	"go-humas-be/app/module/provinces/service"
	"go.uber.org/fx"
)

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

// register bulky of Provinces module
var NewProvincesModule = fx.Options(
	// register repository of Provinces module
	fx.Provide(repository.NewProvincesRepository),

	// register service of Provinces module
	fx.Provide(service.NewProvincesService),

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

	// register router of Provinces module
	fx.Provide(NewProvincesRouter),
)

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

// register routes of Provinces module
func (_i *ProvincesRouter) RegisterProvincesRoutes() {
	// define controllers
	provincesController := _i.Controller.Provinces

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