import Fastify, { FastifyInstance } from 'fastify';
import cors from '@fastify/cors';
import helmet from '@fastify/helmet';
import rateLimit from '@fastify/rate-limit';
import healthRoutes from './routes/health';
import importRoutes from './routes/import';

export function buildApp(): FastifyInstance {
  const app: FastifyInstance = Fastify({
    logger: false,
  });

  void app.register(cors, { origin: true });
  void app.register(helmet);
  void app.register(rateLimit, { max: 1000, timeWindow: '1 minute' });
  void app.register(healthRoutes, { prefix: '/api' });
  void app.register(importRoutes, { prefix: '/api' });

  return app;
}

/**
 * Metadatos:
 * Autor: GitHub Copilot
 * Última actualización: 2026-02-07
 */
