import { NextResponse } from 'next/server'; export async function GET(request) { try { const { searchParams } = new URL(request.url); const symbol = searchParams.get('symbol') || 'SOLUSD'; const timeframe = searchParams.get('timeframe') || '60'; // 1h default console.log(`🔍 Getting latest AI analysis for ${symbol} on ${timeframe} timeframe...`); // Get REAL analysis from screenshot system const screenshotResponse = await fetch(`${process.env.APP_URL || 'http://localhost:3000'}/api/enhanced-screenshot`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ symbol, timeframe, layouts: ['ai', 'diy'], analyze: true }) }); if (!screenshotResponse.ok) { throw new Error('Failed to get real screenshot analysis'); } const screenshotData = await screenshotResponse.json(); if (!screenshotData.success || !screenshotData.analysis) { throw new Error('No analysis data from screenshot system'); } // Extract real analysis data const analysis = screenshotData.analysis; return NextResponse.json({ success: true, data: { symbol, timeframe, timestamp: new Date().toISOString(), analysis: analysis, screenshots: screenshotData.screenshots, source: 'REAL_SCREENSHOT_ANALYSIS' } }); } catch (error) { console.error('Error getting latest AI analysis:', error); return NextResponse.json({ success: false, error: error.message }, { status: 500 }); } }