export default defineEventHandler(async (event) => {
  console.log('🏥 Health check requested at:', new Date().toISOString());
  
  try {
    const config = useRuntimeConfig();
    
    // Basic health check - can be expanded to check database, storage, etc.
    const health = {
      status: 'healthy',
      timestamp: new Date().toISOString(),
      uptime: process.uptime(),
      version: process.version,
      environment: process.env.NODE_ENV,
      port: process.env.NUXT_PORT || process.env.PORT || 6060,
      checks: {
        server: 'healthy',
        config: {
          keycloak: !!config.keycloak?.issuer,
          nocodb: !!config.nocodb?.url,
          session: !!config.sessionSecret,
          encryption: !!config.encryptionKey,
        },
        // Add more checks as needed
        // database: await checkDatabase(),
        // storage: await checkStorage(),
        // auth: await checkAuth(),
      },
    };

    console.log('✅ Health check passed:', health.status);
    return health;
  } catch (error) {
    console.error('❌ Health check failed:', error);
    
    throw createError({
      statusCode: 503,
      statusMessage: 'Service Unavailable',
      data: {
        status: 'unhealthy',
        timestamp: new Date().toISOString(),
        error: error instanceof Error ? error.message : 'Unknown error',
      },
    });
  }
});
