import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';

/**
 * Liveness endpoint. Returns 200 OK with minimal process metadata.
 * Intentionally cheap (no DB / Redis / downstream check) so it can
 * be hit by container orchestrators (Kubernetes, Compose healthcheck)
 * without amplifying load on backing services.
 *
 * A separate `/readiness` endpoint will land alongside the first
 * dependency that has a readiness story to tell (Postgres pool warm,
 * Redis connection established, etc.).
 */
@ApiTags('health')
@Controller('health')
export class HealthController {
  private readonly startedAt = Date.now();

  @ApiOperation({ summary: 'Liveness probe (no backing-service checks)' })
  @Get()
  liveness(): { status: 'ok'; uptimeSeconds: number; service: string; version: string } {
    return {
      status: 'ok',
      uptimeSeconds: Math.floor((Date.now() - this.startedAt) / 1000),
      service: process.env['OTEL_SERVICE_NAME'] ?? 'portal-bff',
      version: process.env['OTEL_SERVICE_VERSION'] ?? 'dev',
    };
  }
}
