import { getAllSiteConfigs } from '../../database/queries/siteconfig'
import { handleApiError, createSuccessResponse } from '../../utils/errors'

interface SiteConfigResponse {
  key: string
  value: string
}

export default defineEventHandler(async () => {
  try {
    const configs = await getAllSiteConfigs()

    return createSuccessResponse<SiteConfigResponse[]>(
      configs.map(config => ({
        key: config.key,
        value: config.value
      }))
    )
  } catch (error) {
    throw handleApiError(error)
  }
})
