import express from 'express';
import cors from 'cors';
import { PrismaClient } from '@prisma/client';
import dotenv from 'dotenv';

dotenv.config();

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

app.use(cors());
app.use(express.json());

// Basic health check endpoint
app.get('/api/health', (req, res) => {
  res.json({ status: 'ok', message: '5651 SaaS API is running' });
});

import tenantRoutes from './routes/tenantRoutes';
import deviceRoutes from './routes/deviceRoutes';

app.use('/api/tenants', tenantRoutes);
app.use('/api/devices', deviceRoutes);

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