import { Controller, Get } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service';
import { Public } from '../../shared/guards/admin-auth.guard';

@ApiTags('Health')
@Controller('health')
export class HealthController {
  constructor(private readonly prisma: PrismaService) {}

  @Get()
  @Public()
  @ApiOperation({ summary: '健康检查' })
  async check() {
    const status = { status: 'healthy' as 'healthy' | 'unhealthy', timestamp: new Date().toISOString(), services: { database: 'up' as 'up' | 'down' } };
    try { await this.prisma.$queryRaw`SELECT 1`; } catch { status.services.database = 'down'; status.status = 'unhealthy'; }
    return status;
  }

  @Get('ready')
  @Public()
  @ApiOperation({ summary: '就绪检查' })
  async ready() { return { ready: true }; }
}
