import { Controller, Get, NotFoundException, Param, Res } from '@nestjs/common';
import type { Response } from 'express';
import { ManualService } from './manual.service';

/**
 * Capturas y guías paso a paso del manual (plan §6.9). Públicas: un <img> no manda el token, y son pantallas
 * de la empresa de demostración de test, sin datos de clientes. Nombre validado (sin rutas).
 */
@Controller({ path: 'manual', version: '1' })
export class ManualController {
  constructor(private readonly manual: ManualService) {}

  @Get('capturas/:nombre')
  captura(@Param('nombre') nombre: string, @Res() res: Response) {
    const f = this.manual.rutaCaptura(nombre);
    if (!f) throw new NotFoundException();
    res.setHeader('Cache-Control', 'public, max-age=86400');
    res.sendFile(f);
  }

  /** Una guía paso a paso: textos, imágenes (por /capturas) y recuadros a resaltar. */
  @Get('guias/:id')
  guia(@Param('id') id: string, @Res({ passthrough: true }) res: Response) {
    const g = this.manual.guia(id);
    if (!g) throw new NotFoundException();
    res.setHeader('Cache-Control', 'public, max-age=3600');
    return g;
  }
}
