import { Controller, Get } from '@nestjs/common';
import { PrismaService } from './prisma/prisma.service';
import { CapabilityProviderRegistry } from './capability/capability.registry';

@Controller('health')
export class HealthController {
  constructor(
    private readonly prisma: PrismaService,
    private readonly providers: CapabilityProviderRegistry,
  ) {}

  @Get()
  async check(): Promise<{ status: string; db: boolean; egressProviders: Record<string, string> }> {
    let db = false;
    try {
      await this.prisma.$queryRaw`SELECT 1`;
      db = true;
    } catch {
      db = false;
    }
    // Ops view: which provider (sandbox vs http) backs each egress channel.
    return { status: 'ok', db, egressProviders: this.providers.bindings() };
  }
}
