package districts

import (
	"narasi-ahli-be/app/module/districts/controller"
	"narasi-ahli-be/app/module/districts/repository"
	"narasi-ahli-be/app/module/districts/service"

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

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

// NewDistrictsModule register bulky of Districts module
var NewDistrictsModule = fx.Options(
	// register repository of Districts module
	fx.Provide(repository.NewDistrictsRepository),

	// register service of Districts module
	fx.Provide(service.NewDistrictsService),

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

	// register router of Districts module
	fx.Provide(NewDistrictsRouter),
)

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

// RegisterDistrictsRoutes register routes of Districts module
func (_i *DistrictsRouter) RegisterDistrictsRoutes() {
	// define controllers
	districtsController := _i.Controller.Districts

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