/**
 * SDK Export Utilities
 * Barrel module — re-exports PDF, ZIP, and helpers
 */

import { SDKState } from './types'
import { ExportOptions } from './export-types'
import { exportToPDF } from './export-pdf'
import { exportToZIP } from './export-zip'

// Re-export all public API
export type { ExportOptions } from './export-types'
export { exportToPDF } from './export-pdf'
export { exportToZIP } from './export-zip'

// =============================================================================
// DOWNLOAD HELPER
// =============================================================================

export async function downloadExport(
  state: SDKState,
  format: 'json' | 'pdf' | 'zip',
  options: ExportOptions = {}
): Promise<void> {
  let blob: Blob
  let filename: string

  const timestamp = new Date().toISOString().slice(0, 10)

  switch (format) {
    case 'json':
      blob = new Blob([JSON.stringify(state, null, 2)], { type: 'application/json' })
      filename = `ai-compliance-sdk-${timestamp}.json`
      break

    case 'pdf':
      blob = await exportToPDF(state, options)
      filename = `ai-compliance-sdk-${timestamp}.pdf`
      break

    case 'zip':
      blob = await exportToZIP(state, options)
      filename = `ai-compliance-sdk-${timestamp}.zip`
      break

    default:
      throw new Error(`Unknown export format: ${format}`)
  }

  // Create download link
  const url = URL.createObjectURL(blob)
  const link = document.createElement('a')
  link.href = url
  link.download = filename
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
  URL.revokeObjectURL(url)
}
