/**
 * Get tables from a specific Metabase database
 */
export default defineEventHandler(async (event) => {
  const databaseId = getRouterParam(event, 'databaseId')

  if (!databaseId) {
    throw createError({
      statusCode: 400,
      statusMessage: 'Database ID is required'
    })
  }

  try {
    const metadata = await getMetabaseTables(parseInt(databaseId))
    return metadata
  } catch (error: any) {
    console.error(`[API] Failed to get tables for database ${databaseId}:`, error)
    throw createError({
      statusCode: error.statusCode || 500,
      statusMessage: error.statusMessage || 'Failed to fetch tables'
    })
  }
})
