import Fastify from 'fastify';
import { config } from './config/index.js';
import { healthRoutes } from './routes/health.routes.js';
import { invoiceRoutes } from './routes/invoice.routes.js';
import { errorHandler } from './errors/error-handler.js';

export function buildApp() {
  const app = Fastify({
    logger: {
      level: config.logLevel,
    },
  });

  // Error Handler
  app.setErrorHandler(errorHandler);

  // Routes registrieren
  app.register(healthRoutes);
  app.register(invoiceRoutes);

  return app;
}
