package purchases

import (
	"github.com/gofiber/fiber/v2"

	m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
	controller "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/controllers"
	service "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/services"
	user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
)

func Routes(router fiber.Router, purchaseService service.PurchaseService, userService user.UserService) {
	ctrl := controller.NewPurchaseController(purchaseService)

	route := router.Group("/purchases")
	route.Use(m.Auth(userService))

	route.Get("/", m.RequirePermissions(m.P_PurchaseGetAll), ctrl.GetAll)
	route.Get("/:id", m.RequirePermissions(m.P_PurchaseGetOne), ctrl.GetOne)
	route.Post("/", m.RequirePermissions(m.P_PurchaseCreateOne), ctrl.CreateOne)
	route.Post("/:id/approvals/staff", m.RequirePermissions(m.P_PurchaseApprovalStaff), ctrl.ApproveStaffPurchase)
	route.Post("/:id/approvals/manager", m.RequirePermissions(m.P_PurchaseApprovalManager), ctrl.ApproveManagerPurchase)
	route.Post("/:id/receipts", m.RequirePermissions(m.P_PurchaseReceive), ctrl.ReceiveProducts)
	route.Delete("/:id", m.RequirePermissions(m.P_PurchaseDeleteOne), ctrl.DeletePurchase)
	route.Delete("/:id/items", m.RequirePermissions(m.P_PurchaseItemDeleteOne), ctrl.DeleteItems)
}
