import { sql } from '@vercel/postgres'; export default async function handler(req, res) { if (req.method !== 'GET') { return res.status(405).json({ error: 'Method not allowed' }); } const { id } = req.query; try { const result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, quantity FROM cards WHERE id = ${id} `; if (result.rows.length === 0) { return res.status(404).json({ error: 'Card not found' }); } const card = result.rows[0]; // Parse colors if it's a JSON string if (card.colors && typeof card.colors === 'string') { try { card.colors = JSON.parse(card.colors); } catch (e) { card.colors = []; } } res.status(200).json(card); } catch (error) { console.error('Error fetching card:', error); res.status(500).json({ error: 'Failed to fetch card' }); } }