import { Controller, Get } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import * as Sentry from '@sentry/nestjs';

@ApiTags('Health')
@Controller('health')
export class HealthController {
  @Get()
  @ApiOperation({ summary: 'Health check endpoint' })
  @ApiResponse({
    status: 200,
    description: 'Health status returned successfully',
    schema: {
      type: 'object',
      properties: {
        status: { type: 'string', example: 'ok' },
        timestamp: { type: 'string', example: '2024-01-01T00:00:00.000Z' },
        uptime: { type: 'number', example: 123.456 },
      },
    },
  })
  check() {
    return {
      status: 'ok',
      timestamp: new Date().toISOString(),
      uptime: process.uptime(),
    };
  }

  // ------------------------------------------------------
  // 🔥 Endpoint pour tester l’intégration Sentry
  // ------------------------------------------------------
  @Get('debug-sentry')
  @ApiOperation({ summary: 'Trigger a test error sent to Sentry' })
  @ApiResponse({
    status: 500,
    description: 'Intentional Sentry test error',
  })
  debugSentry() {
    // Log facultatif pour vérifier que Sentry capture aussi les logs
    Sentry.logger.info('User triggered debug-sentry endpoint', {
      action: 'debug_sentry',
    });

    // Tu peux aussi envoyer une métrique custom (nouvelle fonctionnalité Sentry)
    Sentry.metrics.count('debug_sentry_hit', 1);

    // Cette erreur sera captée automatiquement par SentryGlobalFilter
    throw new Error('Sentry test error triggered from /health/debug-sentry');
  }
}
