package api

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

	"wucher/internal/service"
	"wucher/internal/transport/http/handlers"
	"wucher/internal/transport/http/middleware"
)

func registerWOPIRoutes(app fiber.Router, takeoverHandler *handlers.TakeoverHandler, wopiSvc *service.WOPIService) {
	wopi := app.Group("/wopi", middleware.WOPIRequired(wopiSvc))
	if wopiSvc != nil {
		wopi.Use(middleware.WOPIRequestBodyLimit(wopiSvc.MaxBodyBytes()))
	}
	readOnly := wopi.Group("", middleware.WOPIPermissionRequired(service.WOPIPermissionRead))
	writeOnly := wopi.Group("", middleware.WOPIPermissionRequired(service.WOPIPermissionWrite))

	readOnly.Get("/files/:fileId", takeoverHandler.CheckWOPIFileInfo)
	readOnly.Get("/files/:fileId/contents", takeoverHandler.GetWOPIContents)
	writeOnly.Post("/files/:fileId/contents", takeoverHandler.PutWOPIContents)
	writeOnly.Post("/files/:fileId", takeoverHandler.PostWOPIFile)
}
