package cities

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

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

// register bulky of Cities module
var NewCitiesModule = fx.Options(
	// register repository of Cities module
	fx.Provide(repository.NewCitiesRepository),

	// register service of Cities module
	fx.Provide(service.NewCitiesService),

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

	// register router of Cities module
	fx.Provide(NewCitiesRouter),
)

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

// register routes of Cities module
func (_i *CitiesRouter) RegisterCitiesRoutes() {
	// define controllers
	citiesController := _i.Controller.Cities

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