import 'dotenv/config';
import Fastify from 'fastify';
import cors from '@fastify/cors';
import documentRoutes from './routes/documents.js';

const PORT = parseInt(process.env['INGESTION_PORT'] ?? '3001', 10);

async function start(): Promise<void> {
  const app = Fastify({ logger: true });

  await app.register(cors, { origin: true });
  await app.register(documentRoutes);

  await app.listen({ port: PORT, host: '0.0.0.0' });
}

start().catch((err: unknown) => {
  console.error('Failed to start ingestion service:', err);
  process.exit(1);
});
