// Admin · Uploads — the generalized image upload used by the rich-text editors
// (wiki, CMS pages). Returns { url }, where the posts-specific sibling
// POST /admin/posts/upload returns { image_url }; both write to the same
// directory through the shared multer config in imageUpload.js.
//
// Mounted at /api/v1/admin/uploads by admin/index.js, which already applied
// `noindex, isLoggedIn, staffOnly`. No extra gate — same editor tier as posts.
//
// The swagger tag stays 'Admin · Posts', matching the committed spec. Retagging
// it would be a real OpenAPI diff, not a route move, so it does not belong in a
// split PR whose acceptance criterion is a byte-identical spec.

const express = require('express')

const ctrl = require('./admin.controller')
const { upload } = require('./imageUpload')

const uploadsRouter = express.Router()

uploadsRouter.post(
  '/',
  // #swagger.tags = ['Admin · Posts']
  // #swagger.summary = 'Upload an image for rich-text editors (multipart)'
  // #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
  /* #swagger.requestBody = { required: true, content: { "multipart/form-data": { schema: { type: "object", properties: { image: { type: "string", format: "binary" } } } } } } */
  /* #swagger.responses[201] = { description: 'Stored file URL', content: { "application/json": { schema: { $ref: "#/components/schemas/UploadResponse" } } } } */
  /* #swagger.responses[400] = { description: 'No file / disallowed type', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
  /* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
  upload.single('image'),
  ctrl.uploadFile,
)

module.exports = uploadsRouter
