import type { APIRoute } from 'astro';
import { trendingAnalyticsService } from '../../../lib/analytics';

export const GET: APIRoute = async () => {
  try {
    // This endpoint should be called by a cron job or background service
    // It updates popularity scores for all events

    await trendingAnalyticsService.batchUpdatePopularityScores();

    return new Response(JSON.stringify({
      success: true,
      message: 'Popularity scores updated successfully',
      timestamp: new Date().toISOString()
    }), {
      status: 200,
      headers: {
        'Content-Type': 'application/json'
      }
    });
  } catch (error) {

    return new Response(JSON.stringify({
      success: false,
      error: 'Failed to update popularity scores',
      timestamp: new Date().toISOString()
    }), {
      status: 500,
      headers: {
        'Content-Type': 'application/json'
      }
    });
  }
};