package agent

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

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

type AgentRouter struct {
	App        fiber.Router
	Controller *controller.Controller
}

var NewAgentModule = fx.Options(
	// register repository of Agent module
	fx.Provide(repository.NewAgentRepository),

	// register service of Agent module
	fx.Provide(service.NewAgentService),

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

	// register router of Agent module
	fx.Provide(NewAgentRouter),
)

func NewAgentRouter(fiber *fiber.App, controller *controller.Controller) *AgentRouter {
	return &AgentRouter{
		App:        fiber,
		Controller: controller,
	}
}

func (_i *AgentRouter) RegisterAgentRoutes() {
	agentController := _i.Controller.Agent

	_i.App.Route("/agent", func(router fiber.Router) {
		router.Get("/", agentController.All)
		router.Get("/:id", agentController.Show)
		router.Get("/agent_id/:agentId", agentController.FindByAgentId)
		router.Put("/:id", agentController.Update)
		router.Post("/", agentController.Save)
		router.Delete("/:id", agentController.Delete)
	})
}