import axios from 'axios'; import type { CardsResponse } from '@/types/pokemon'; const BASE = 'https://api.pokemontcg.io/v2'; export type FetchCardsParams = { q?: string; page?: number; pageSize?: number; }; export async function fetchMagikarpCards(params: FetchCardsParams = {}): Promise { const { q, page = 1, pageSize = 50 } = params; // Keep query minimal to avoid parser errors on API side const parts = [ 'name:magikarp', ]; if (q) parts.push(q); const url = `${BASE}/cards`; const headers: Record = {}; const apiKey = process.env.POKEMON_TCG_API_KEY || process.env.NEXT_PUBLIC_POKEMON_TCG_API_KEY; if (apiKey) headers['X-Api-Key'] = apiKey; const { data } = await axios.get(url, { params: { q: parts.join(' '), page, pageSize }, headers, }); return data; }