// Public · Posts — the published news / five-on-friday / newsletter / screenshots
// feed. The read-only counterpart of admin/posts.router.js, sharing the same
// posts model through public.controller.
//
// Mounted at /api/v1/public/posts by public/index.js. No group gate: this is the
// anonymous public surface. `siteMode` is applied per route — during maintenance
// only an admin with a valid session sees content.

const express = require('express')

const ctrl = require('./public.controller')
const siteMode = require('../../../middleware/siteMode')

const postsRouter = express.Router()

postsRouter.get(
  '/:category',
  // #swagger.tags = ['Public']
  // #swagger.summary = 'List published posts in a category'
  // #swagger.description = 'Gated by site mode: during maintenance only admins with a valid session see content.'
  // #swagger.parameters['category'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'news | five-on-friday | newsletter | screenshots' }
  /* #swagger.responses[200] = { description: 'Published posts', content: { "application/json": { schema: { type: "array", items: { $ref: "#/components/schemas/Post" } } } } } */
  /* #swagger.responses[404] = { description: 'Unknown category', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
  siteMode,
  ctrl.getPosts,
)
postsRouter.get(
  '/:category/:idOrSlug',
  // #swagger.tags = ['Public']
  // #swagger.summary = 'Get a single published post'
  // #swagger.parameters['category'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Post category.' }
  // #swagger.parameters['idOrSlug'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Numeric id or slug.' }
  /* #swagger.responses[200] = { description: 'The post', content: { "application/json": { schema: { $ref: "#/components/schemas/Post" } } } } */
  /* #swagger.responses[404] = { description: 'Unknown category or post not found', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
  siteMode,
  ctrl.getPost,
)

module.exports = postsRouter
