export interface LatestRelease {
  repo: string
  latest_version: string
  changelog: string
  published_at: string
  attachments: string[]
}

export interface ApiResponse {
  results: Array<{
    repo: string
    success: boolean
    latest_release?: LatestRelease
    error?: string
  }>
}

export async function fetchResourceReleaseData(
  repos: string[],
): Promise<ApiResponse> {
  const response = await fetch('https://gh-info.okk.cool/repos/batch', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      repos: repos,
      fields: ['latest_release'],
    }),
  })

  if (!response.ok) {
    throw new Error(`API 请求失败: ${response.status}`)
  }

  return await response.json()
}
