// Public · Modules — the installed-module list a client feature-detects against.
//
// Mounted at /api/v1/public/modules by public/index.js. One route, and it owns a
// prefix rather than sitting beside /settings and /version in site.router.js —
// which is the point of the file existing at all. The loader asks the LIVE
// public tier router whether a prefix is already core's (`ownedByCore`,
// modules/loader.js), and it skips root-mounted layers because a `use('/', …)`
// matches every path. A route declared inside the root-mounted site router is
// therefore invisible to that probe; a real `use('/modules', …)` layer is not.
// So mounting it here is what makes "no module may ever claim /modules" an
// enforced rule instead of a convention.
//
// No siteMode gate and no database — see modules.controller.js for why.

const express = require('express')

const ctrl = require('./modules.controller')

const modulesRouter = express.Router()

modulesRouter.get(
  '/',
  // #swagger.tags = ['Public']
  // #swagger.summary = 'Installed modules (id, version, capabilities)'
  // #swagger.description = 'The modules this backend is currently SERVING, in scan order. A module that is disabled or failed to load is absent rather than listed with a state — its routes and nav are absent too, so the client renders a site without that capability. `capabilities` are opaque strings declared by the module for clients (the SPA, the Android app) to feature-detect against; treat an unknown one as absent. Database-free and never gated by site mode, so a client can feature-detect during maintenance.'
  /* #swagger.responses[200] = { description: 'The started modules', content: { "application/json": { schema: { $ref: "#/components/schemas/PublicModules" } } } } */
  ctrl.getModules,
)

module.exports = modulesRouter
