// Proxy endpoint for the mobile APK release history (avoids CORS issues), mirroring app-version.get.ts.
// Returns the array of previously-released versions from the update server's history.json, each entry:
//   { versionName, versionCode, releaseDate, releaseNotes, apkUrl }  (apkUrl is relative, e.g. history/...)
// The in-app admin-only "Versionsverlauf" reads this to let an admin re-install an older build.
// Fail-soft: if history.json doesn't exist yet (404) we return [] rather than erroring.
export default defineEventHandler(async (event) => {
  try {
    const response = await fetch('https://www.logyou.de/logship/history.json', { cache: 'no-store' } as any)
    if (response.status === 404) return []
    if (!response.ok) {
      throw new Error(`Failed to fetch history: ${response.status}`)
    }
    const data = await response.json()
    return Array.isArray(data) ? data : []
  } catch (error: any) {
    console.error('Error fetching app version history:', error)
    // Fail-soft so the dashboard never breaks on a missing/unreachable manifest.
    return []
  }
})
