import type { Aircraft } from '../types';

interface AircraftApiResponse {
  region: string;
  count: number;
  lastUpdated: number;
  aircraft: Aircraft[];
}

export async function fetchAircraftFromBackend(region: 'iran' | 'korea'): Promise<Aircraft[]> {
  try {
    const res = await fetch(`/api/kcg/aircraft?region=${region}`, {
      credentials: 'include',
    });
    if (!res.ok) return [];
    const data: AircraftApiResponse = await res.json();
    return data.aircraft;
  } catch {
    return [];
  }
}
