import express from 'express';
import cors from 'cors';
import { server, erp, nocodb } from './config';
import erpRoutes from './routes/erp';
import etlRoutes from './routes/etl';
import seasonsRoutes from './routes/seasons';

const app = express();
app.use(cors());
app.use(express.json());

// Mount routes
app.use('/api/erp', erpRoutes);
app.use('/api/etl', etlRoutes);
app.use('/api/seasons', seasonsRoutes);

app.listen(server.port, () => {
  console.log(`\nServer running on http://localhost:${server.port}`);

  if (erp.apiUrl && erp.username) {
    console.log('  ERP: configured');
  } else {
    console.log('  ERP: WARNING — not configured');
  }

  if (nocodb.url && nocodb.token) {
    console.log('  NocoDB: configured');
    console.log('  POST /api/etl/sync?mode=full|incremental');
  } else {
    console.log('  NocoDB: WARNING — not configured');
  }
});
