package users

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

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

// register bulky of Users module
var NewUsersModule = fx.Options(
	// register repository of Users module
	fx.Provide(repository.NewUsersRepository),

	// register service of Users module
	fx.Provide(service.NewUsersService),

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

	// register router of Users module
	fx.Provide(NewUsersRouter),
)

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

// register routes of Users module
func (_i *UsersRouter) RegisterUsersRoutes() {
	// define controllers
	usersController := _i.Controller.Users

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