import express from 'express';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import { server, erp, nocodb } from './config';
import authRoutes from './routes/auth';
import erpRoutes from './routes/erp';
import etlRoutes from './routes/etl';
import seasonsRoutes from './routes/seasons';

const app = express();
app.use(cors({ origin: true, credentials: true }));
app.use(cookieParser());
app.use(express.json());

// Mount routes
app.use('/auth', authRoutes);
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');
  }
});
