const express = require('express');
const cors = require('cors');
const path = require('path');

const authRoutes = require('./routes/auth');
const candidateRoutes = require('./routes/candidates');
const positionRoutes = require('./routes/positions');
const voteRoutes = require('./routes/vote');

const app = express();

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

// Serve static files from the public directory (for images)
app.use('/public', express.static(path.join(__dirname, 'public')));

// Routes
app.use('/api/auth', authRoutes);
app.use('/api/candidates', candidateRoutes);
app.use('/api/positions', positionRoutes);
app.use('/api/vote', voteRoutes);

// Basic health check route
app.get('/api/health', (req, res) => {
  res.json({ status: 'ok', message: 'Election server is running' });
});

module.exports = app;
