package approval_workflows

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

// ApprovalWorkflowsRouter struct of ApprovalWorkflowsRouter
type ApprovalWorkflowsRouter struct {
	App        fiber.Router
	Controller controller.ApprovalWorkflowsController
}

// NewApprovalWorkflowsModule register bulky of ApprovalWorkflows module
var NewApprovalWorkflowsModule = fx.Options(
	// register repository of ApprovalWorkflows module
	fx.Provide(repository.NewApprovalWorkflowsRepository),

	// register service of ApprovalWorkflows module
	fx.Provide(service.NewApprovalWorkflowsService),

	// register controller of ApprovalWorkflows module
	fx.Provide(controller.NewApprovalWorkflowsController),

	// register router of ApprovalWorkflows module
	fx.Provide(NewApprovalWorkflowsRouter),
)

// NewApprovalWorkflowsRouter init ApprovalWorkflowsRouter
func NewApprovalWorkflowsRouter(fiber *fiber.App, controller controller.ApprovalWorkflowsController) *ApprovalWorkflowsRouter {
	return &ApprovalWorkflowsRouter{
		App:        fiber,
		Controller: controller,
	}
}

// RegisterApprovalWorkflowsRoutes register routes of ApprovalWorkflows module
func (_i *ApprovalWorkflowsRouter) RegisterApprovalWorkflowsRoutes() {
	// define controllers
	approvalWorkflowsController := _i.Controller

	// define routes
	_i.App.Route("/approval-workflows", func(router fiber.Router) {
		router.Get("/", approvalWorkflowsController.All)
		router.Get("/default", approvalWorkflowsController.GetDefault)
		router.Get("/:id", approvalWorkflowsController.Show)
		router.Get("/:id/with-steps", approvalWorkflowsController.GetWithSteps)
		router.Post("/", approvalWorkflowsController.Save)
		router.Post("/with-steps", approvalWorkflowsController.SaveWithSteps)
		router.Put("/:id", approvalWorkflowsController.Update)
		router.Put("/:id/with-steps", approvalWorkflowsController.UpdateWithSteps)
		router.Put("/:id/set-default", approvalWorkflowsController.SetDefault)
		router.Put("/:id/activate", approvalWorkflowsController.Activate)
		router.Put("/:id/deactivate", approvalWorkflowsController.Deactivate)
		router.Delete("/:id", approvalWorkflowsController.Delete)
	})
}