import express from 'express'
import dotenv from 'dotenv'
dotenv.config()
import cors from 'cors'
import connectToDb from './config/database.js'
import inventoryRoutes from './routes/inventoryRoutes.js'
import serviceRoutes from './routes/serviceRoutes.js'
import authRoutes from './routes/authRoutes.js'
import garageRoutes from './routes/garageRoutes.js' // Import garage routes
import cookieParser from 'cookie-parser'
import analyticsRoutes from './routes/analyticsRoutes.js'

const app = express()

// Middleware
app.use(express.json())
app.use(cors({
    origin: 'http://localhost:5173', // your frontend URL
    credentials: true
}));
app.use(cookieParser());
app.use('/uploads', express.static('uploads'));

// Connect to database
connectToDb()

// Routes
app.use('/api/inventory', inventoryRoutes)
app.use('/api/service', serviceRoutes)
app.use('/api/garage', garageRoutes) // Add garage routes
app.use('/api/auth', authRoutes) // Add auth routes
app.use('/api/analytics', analyticsRoutes) // Add analytics routes

app.listen(process.env.PORT, () => {
    console.log("Server start on :", process.env.PORT)
})
