/**
 * GET /spaces/:slug/gallery — public, unauthenticated, no version prefix (§1, §4a).
 * `?category=<slug>` is an additive filter; the frontend never sends it.
 */
import { Router } from 'express';
import { asyncHandler } from '../../lib/asyncHandler';
import { getSpaceGallery } from './gallery.service';

export const galleryRouter = Router();

galleryRouter.get(
  '/spaces/:slug/gallery',
  asyncHandler(async (req, res) => {
    const category = typeof req.query.category === 'string' ? req.query.category : undefined;
    const payload = await getSpaceGallery(req.params.slug, category);
    res.set('Cache-Control', 'public, max-age=300, stale-while-revalidate=86400');
    res.json(payload);
  }),
);
