/**
 * Transparency Dashboard API
 * GET /api/transparency/dashboard
 *
 * Returns comprehensive transparency metrics for the entire platform.
 */

import type { NextApiRequest, NextApiResponse } from 'next';
import { getTransparencyDashboard } from '../../../lib/transparency';

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== 'GET') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  try {
    const dashboard = getTransparencyDashboard();
    const data = await dashboard.getDashboard();

    // Add cache headers for performance
    res.setHeader('Cache-Control', 'public, s-maxage=10, stale-while-revalidate=59');

    return res.status(200).json({
      success: true,
      data
    });
  } catch (error) {
    console.error('[API] Dashboard error:', error);
    return res.status(500).json({
      success: false,
      error: 'Failed to fetch dashboard data'
    });
  }
}
