import { Controller, Get, ServiceUnavailableException } from '@nestjs/common';
import { HealthService } from './health.service';
import { Public } from '@common/decorators/public.decorator';

@Controller('health')
export class HealthController {
  constructor(private readonly healthService: HealthService) {}

  @Get()
  @Public()
  async check() {
    return this.healthService.check();
  }

  /**
   * 任一关键依赖 down → 503，body 仍透传完整 services 详情供 LB / 监控读取。
   */
  @Get('detailed')
  @Public()
  async detailedCheck() {
    const status = await this.healthService.detailedCheck();
    if (status.status === 'unhealthy') {
      throw new ServiceUnavailableException(status);
    }
    return status;
  }

  @Get('ready')
  @Public()
  async readiness() {
    return this.healthService.readinessCheck();
  }

  @Get('live')
  @Public()
  async liveness() {
    return this.healthService.livenessCheck();
  }
}
