import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import { initialize } from './configs/db.js';
import cookieParser from "cookie-parser";
import authRoute from './routes/auth.route.js';
import productRoute from './routes/product.route.js';
import salesRoute from './routes/sale.route.js';
import customerRoute from './routes/customer.route.js';
import reportRoute from './routes/report.route.js';

dotenv.config();

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

app.use(express.json());
app.use(cookieParser());
app.use(cors({
  origin: 'http://localhost:5173',
  credentials: true
}));

app.use("/api/auth", authRoute);
app.use("/api/products", productRoute);
app.use("/api/sales", salesRoute);
app.use("/api/customers", customerRoute);
app.use("/api/reports", reportRoute);

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}`);
  initialize();
});