const express = require('express');
const fs = require('fs');
const path = require('path');
const router = express.Router();

const musicDir = path.join(__dirname, '..', '..', 'media', 'music');

// GET /api/music/manifest — returns the music manifest array
router.get('/manifest', (req, res) => {
  const manifestPath = path.join(musicDir, 'manifest.json');
  try {
    if (!fs.existsSync(manifestPath)) {
      return res.status(404).json({ error: 'Music manifest not found' });
    }
    const data = fs.readFileSync(manifestPath, 'utf-8');
    const manifest = JSON.parse(data);
    return res.json(manifest);
  } catch (err) {
    console.error('Failed to read music manifest:', err);
    return res.status(500).json({ error: 'Failed to read music manifest' });
  }
});

module.exports = router;