import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import customerRoutes from './routes/customers.js';
import projectRoutes from './routes/projects.js';
import invoiceRoutes from './routes/invoices.js';
import expenseRoutes from './routes/expenses.js';
import quotationRoutes from './routes/quotations.js';
import pettyCashRoutes from './routes/petty_cash.js';
import receiptRoutes from './routes/receipts.js';
import documentRoutes from './routes/documents.js';
import authRoutes from './routes/auth.js';
import settingsRoutes from './routes/settings.js';
import aiRoutes from './routes/ai.js';
import bankRoutes from './routes/bank.js';
import vendorRoutes from './routes/vendors.js';
import materialRoutes from './routes/materials.js';
import lpoRoutes from './routes/lpos.js';
import path from 'path';

dotenv.config();

const app = express();
const PORT = process.env.PORT || 5000;

app.use(cors());
app.use(express.json());
// Serve uploads directory
app.use('/uploads', express.static('uploads'));

// Routes
app.use('/api/auth', authRoutes);
app.use('/api/customers', customerRoutes);
app.use('/api/projects', projectRoutes);
app.use('/api/invoices', invoiceRoutes);
app.use('/api/expenses', expenseRoutes);
app.use('/api/quotations', quotationRoutes);
app.use('/api/petty-cash', pettyCashRoutes);
app.use('/api/receipts', receiptRoutes);
app.use('/api/documents', documentRoutes);
app.use('/api/settings', settingsRoutes);
app.use('/api/ai', aiRoutes);
app.use('/api/bank', bankRoutes);
app.use('/api/vendors', vendorRoutes);
app.use('/api/materials', materialRoutes);
app.use('/api/lpos', lpoRoutes);

app.get('/api/health', (req, res) => {
    res.json({ status: 'OK', message: 'Server is running' });
});

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