const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const path = require('path');
require('dotenv').config();

const authRoutes = require('./routes/authRoutes');
const categoryRoutes = require('./routes/categoryRoutes');
const subCategoryRoutes = require('./routes/subCategoryRoutes');
const newTourRoutes = require('./routes/newTourRoutes');
const orderRoutes = require('./routes/orderRoutes');
const reservationRoutes = require('./routes/reservationRoutes');
const uploadRoutes = require('./routes/uploadRoutes');
const airlineRoutes = require('./routes/airlineRoutes');
const umreRoutes = require('./routes/umreRoutes');
const hajjRoutes = require('./routes/hajjRoutes');
const pageRoutes = require('./routes/pageRoutes');
const contactRoutes = require('./routes/contactRoutes');
const galleryRoutes = require('./routes/galleryRoutes');
const testimonialRoutes = require('./routes/testimonialRoutes');
const newsletterRoutes = require('./routes/newsletterRoutes');
const cookieConsentRoutes = require('./routes/cookieConsentRoutes');
const faqRoutes = require('./routes/faqRoutes');
const dashboardRoutes = require('./routes/dashboardRoutes');
const visitorRoutes = require('./routes/visitorRoutes');

const app = express();

app.use(cors({
  origin: [
    'https://www.ninovaturizm.com',
    'https://ninovaturizm.com',
    process.env.ADMIN_URL || 'http://localhost:5174'
  ],
  credentials: true
}));
app.use(cookieParser());
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ extended: true, limit: '50mb' }));

// Statik dosya servisi
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));

app.use('/api/auth', authRoutes);
app.use('/api/dashboard', dashboardRoutes);
app.use('/api/categories', categoryRoutes);
app.use('/api/subcategories', subCategoryRoutes);
app.use('/api/tours', newTourRoutes);
app.use('/api/orders', orderRoutes);
app.use('/api/reservations', reservationRoutes);
app.use('/api/upload', uploadRoutes);
app.use('/api/airlines', airlineRoutes);
app.use('/api/umre', umreRoutes);
app.use('/api/hajj', hajjRoutes);
app.use('/api', pageRoutes);
app.use('/api', contactRoutes);
app.use('/api', galleryRoutes);
app.use('/api/testimonials', testimonialRoutes);
app.use('/api/newsletter', newsletterRoutes);
app.use('/api/cookie-consent', cookieConsentRoutes);
app.use('/api/faqs', faqRoutes);
app.use('/api/visitor', visitorRoutes);

app.get('/', (req, res) => {
  res.json({ message: 'Tour Management API' });
});

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});
