import { mapProductForApi, parseMaterialsInput, slugify } from './api/_product-helpers.js'
import { registerAdminNotificationRoutes } from './api/admin/notifications.js'
import { registerAdminTestChecklistRoutes } from './api/admin/test-checklist.js'
import { registerAdminCategoryRoutes } from './api/admin-categories.js'
import { registerAdminGalleryRoutes } from './api/admin-gallery.js'
import { registerAdminOrderRoutes } from './api/admin-orders.js'
import { registerAdminProductRoutes } from './api/admin-products.js'
import { registerAdminProfileRoutes } from './api/admin-profile.js'
import { registerAdminReviewRoutes } from './api/admin-reviews.js'
import { registerAdminUserRoutes } from './api/admin-users.js'
import { registerCatalogSliderRoutes } from './api/catalog-slider.js'
import { registerPublicCatalogRoutes } from './api/public-catalog.js'
import { registerPublicReviewRoutes } from './api/public-reviews.js'
import { registerAuthOAuthRoutes } from './auth-oauth.js'
import { registerAuthPasswordRoutes } from './auth-password.js'
import { registerAuthSessionRoutes } from './auth-session.js'
import { registerAuthRoutes } from './auth.js'

export async function registerApiRoutes(fastify) {
  fastify.decorate('slugify', slugify)
  fastify.decorate('parseMaterialsInput', parseMaterialsInput)
  fastify.decorate('mapProductForApi', mapProductForApi)

  await registerPublicCatalogRoutes(fastify)
  await registerPublicReviewRoutes(fastify)
  await registerCatalogSliderRoutes(fastify)

  await registerAdminProductRoutes(fastify)
  await registerAdminGalleryRoutes(fastify)
  await registerAdminCategoryRoutes(fastify)
  await registerAdminOrderRoutes(fastify)
  await registerAdminReviewRoutes(fastify)
  await registerAdminUserRoutes(fastify)
  await registerAdminNotificationRoutes(fastify)
  await registerAdminTestChecklistRoutes(fastify)
  await registerAdminProfileRoutes(fastify)

  await registerAuthRoutes(fastify)
  await registerAuthSessionRoutes(fastify)
  await registerAuthPasswordRoutes(fastify)
  await registerAuthOAuthRoutes(fastify)
}
