package ai_chat_files

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

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

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

// register bulky of AiChatFiles module
var NewAiChatFilesModule = fx.Options(
	// register repository of AiChatFiles module
	fx.Provide(repository.NewAiChatFilesRepository),

	// register service of AiChatFiles module
	fx.Provide(service.NewAiChatFilesService),
	fx.Provide(service.NewUploadService),
	fx.Provide(service.NewUploadManager),

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

	// register router of AiChatFiles module
	fx.Provide(NewAiChatFilesRouter),
)

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

// register routes of AiChatFiles module
func (_i *AiChatFilesRouter) RegisterAiChatFilesRoutes() {
	// define controllers
	aiChatFilesController := _i.Controller.AiChatFiles

	// define routes
	_i.App.Route("/ai-chat-files", func(router fiber.Router) {
		router.Get("/", aiChatFilesController.All)
		router.Get("/:id", aiChatFilesController.Show)
		router.Post("/:messageId", aiChatFilesController.Save)
		router.Put("/:id", aiChatFilesController.Update)
		router.Delete("/:id", aiChatFilesController.Delete)
		router.Get("/viewer/:filename", aiChatFilesController.Viewer)
		router.Get("/upload-status/:uploadId", aiChatFilesController.GetUploadStatus)
		router.Get("/by-message/:messageId", aiChatFilesController.GetByMessageId)
	})
}
