package ai_chat

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

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

// struct of AIChatRouter
type AIChatRouter struct {
	App        fiber.Router
	Controller controller.AIChatController
}

// register bulky of AI Chat module
var NewAIChatModule = fx.Options(
	// register repository of AI Chat module
	fx.Provide(repository.NewAIChatRepository),

	// register service of AI Chat module
	fx.Provide(service.NewAIChatService),

	// register controller of AI Chat module
	fx.Provide(controller.NewAIChatController),

	// register router of AI Chat module
	fx.Provide(NewAIChatRouter),
)

// init AIChatRouter
func NewAIChatRouter(fiber *fiber.App, controller controller.AIChatController) *AIChatRouter {
	return &AIChatRouter{
		App:        fiber,
		Controller: controller,
	}
}

// register routes of AI Chat module
func (_i *AIChatRouter) RegisterAIChatRoutes() {
	// define controllers
	aiChatController := _i.Controller

	// define routes
	_i.App.Route("/ai-chat", func(router fiber.Router) {
		// Sessions routes
		router.Get("/sessions", aiChatController.GetUserSessions)
		router.Get("/sessions/:id", aiChatController.GetSession)
		router.Post("/sessions", aiChatController.CreateSession)
		router.Put("/sessions/:id", aiChatController.UpdateSession)
		router.Delete("/sessions/:id", aiChatController.DeleteSession)

		// Messages routes
		router.Get("/sessions/:id/messages", aiChatController.GetSessionMessages)
		router.Post("/sessions/messages", aiChatController.SendMessage)
		router.Put("/sessions/messages/:messageId", aiChatController.UpdateMessage)
		router.Delete("/sessions/messages/:messageId", aiChatController.DeleteMessage)

		// Logs routes
		router.Get("/logs", aiChatController.GetUserLogs)
		router.Get("/logs/:id", aiChatController.GetLog)
	})
}
