package routes

import (
	"time"

	"server/internal/auth"
	"server/internal/http/controllers"
	"server/internal/mail"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/middleware/limiter"
)

func registerAuthRoutes(app *fiber.App, authService *auth.Service, mailService *mail.Service) {
	authController := controllers.NewAuthController(authService, mailService)
	authRateLimiter := limiter.New(limiter.Config{
		Max:               10,
		Expiration:        time.Minute,
		LimiterMiddleware: limiter.SlidingWindow{},
	})

	// Typescript: TSEndpoint= path=/auth/login;  name=login; method=POST; request=controllers.LoginRequest; response=auth.TokenPair
	app.Post("/auth/login", authRateLimiter, authController.Login)

	// Typescript: TSEndpoint= path=/auth/refresh; name=refresh; method=POST; request=controllers.RefreshRequest; response=auth.TokenPair
	app.Post("/auth/refresh", authService.Middleware(), authController.Refresh)

	// Typescript: TSEndpoint= path=/auth/me; name=me; method=GET; response=models.UserShort
	app.Get("/auth/me", authService.Middleware(), authController.Me)

	// Typescript: TSEndpoint= path=/auth/register; name=register; method=POST; request=models.UserCreateInput; response=models.UserShort
	app.Post("/auth/register", authRateLimiter, authController.Register)

	// Typescript: TSEndpoint= path=/auth/password/forgot; name=forgotPassword; method=POST; request=controllers.ForgotPasswordRequest; response=controllers.SimpleResponse
	app.Post("/auth/password/forgot", authRateLimiter, authController.ForgotPassword)

	// Typescript: TSEndpoint= path=/auth/password/reset; name=resetPassword; method=POST; request=controllers.ResetPasswordRequest; response=controllers.SimpleResponse
	app.Post("/auth/password/reset", authRateLimiter, authController.ResetPassword)

	// Typescript: TSEndpoint= path=/auth/password/valid; name=validToken; method=POST; request=string; response=controllers.SimpleResponse
	app.Post("/auth/password/valid", authRateLimiter, authController.ValidToken)
}
