package users

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

// 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("/detail/:id", usersController.Show)
		router.Get("/username/:username", usersController.ShowByUsername)
		router.Get("/info", usersController.ShowInfo)
		router.Post("/", usersController.Save)
		router.Put("/:id", usersController.Update)
		router.Post("/login", usersController.Login)
		router.Post("/pareto-login", usersController.ParetoLogin)
		router.Delete("/:id", usersController.Delete)
		router.Post("/save-password", usersController.SavePassword)
		router.Post("/reset-password", usersController.ResetPassword)
		router.Post("/forgot-password", usersController.ForgotPassword)
		router.Post("/otp-request", usersController.OtpRequest)
		router.Post("/otp-validation", usersController.OtpValidation)
		router.Post("/email-validation", usersController.EmailValidation)
		router.Post("/setup-email", usersController.SetupEmail)
	})
}
