import { getAppReadiness } from '~/plugins/00.startup-check.server'

export default defineEventHandler(async (event) => {
  try {
    const readiness = getAppReadiness()
    
    return {
      status: readiness.ready ? 'healthy' : 'starting',
      timestamp: new Date().toISOString(),
      uptime: process.uptime(),
      environment: process.env.NODE_ENV || 'development',
      readiness: {
        ready: readiness.ready,
        keycloakCircuitBreaker: readiness.keycloakCircuitBreaker
      },
      auth: {
        configured: !!process.env.KEYCLOAK_CLIENT_SECRET,
        cookieDomain: process.env.COOKIE_DOMAIN || '.portnimara.dev'
      }
    }
  } catch (error) {
    throw createError({
      statusCode: 500,
      statusMessage: 'Health check failed',
      data: error instanceof Error ? error.message : 'Unknown error'
    })
  }
})
