const express = require('express');
const cors = require('cors');
const userRoutes = require('./src/routes/v1/userRoutes');
const loginRoutes = require('./src/routes/v1/authRoutes');
const carsRoutes = require('./src/routes/v1/carsRoutes');
const collectionRoutes = require('./src/routes/v1/collectionRoutes');
const postRoutes = require('./src/routes/v1/postsRoutes');
const searchRoutes = require('./src/routes/v1/searchRoutes');
const path = require('path');

const app = express();

require('dotenv').config();
const port = process.env.PORT || 5000;

const connectDB = require('./src/db/connectDB');
connectDB(); 

app.use("/uploads", express.static(path.join(__dirname, "uploads")));
app.use(express.json());

app.use(cors());

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.use('/api/v1/users', userRoutes);
app.use('/api/v1/login', loginRoutes);
app.use('/api/v1/cars', carsRoutes);
app.use('/api/v1/collections', collectionRoutes);
app.use('/api/v1/posts', postRoutes);
app.use('/api/v1/search', searchRoutes);

app.use((req, res, next) => {
  res.status(404).json({ message: 'Route not found' });
});

app.listen(port,'0.0.0.0', () => {
  console.log(`RevSocial is listening on port ${port}`);
});