import { Body, Controller, Post } from '@nestjs/common';
import { 
  ApiOperation, 
  ApiResponse, 
  ApiTags, 
  ApiBody 
} from '@nestjs/swagger';
import { CryptoTestService } from './crypto-test.service';
import { CryptoTestDto } from './dto/crypto-test.dto';
import { CryptoTestResult } from './interfaces/crypto-test-result.interface';

@ApiTags('Cryptographic Failures Tests')
@Controller('api/security-tests')
export class CryptoTestController {
  constructor(private readonly cryptoTestService: CryptoTestService) {}

  @Post('crypto-test')
  @ApiOperation({ 
    summary: 'Test a website for cryptographic failures',
    description: 'Analyzes a website for OWASP A02:2021 Cryptographic Failures including TLS configuration, ciphers, security headers, and more.' 
  })
  @ApiBody({ type: CryptoTestDto })
  @ApiResponse({ 
    status: 200, 
    description: 'The cryptographic test results',
  })
  @ApiResponse({ status: 400, description: 'Invalid URL provided' })
  @ApiResponse({ status: 500, description: 'Internal server error' })
  async testCryptographicFailures(@Body() cryptoTestDto: CryptoTestDto): Promise<CryptoTestResult> {
    return this.cryptoTestService.runTest(cryptoTestDto.url);
  }
}