const express = require('express');
const cors = require('cors');
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });

const db = require('./config/db'); 
const authRoutes = require('./routes/auth');
const doctorRoutes = require('./routes/doctors'); 
const patientRoutes = require('./routes/patients'); 
const appointmentRoutes = require('./routes/appointments');
const reportRoutes = require('./routes/reports');


const app = express();

// 🚨 KOSORA HANO (Imyanya y'Isuku): Izi middleware zigomba kuza mbere ya app.use('/api')
app.use(cors({ origin:"http://localhost:5173",credentials:true}));
app.use(express.json()); 

// Hanyuma routes zikaza hasi yazo neza gutya
app.use('/api', authRoutes);
app.use('/api', doctorRoutes);  
app.use('/api', patientRoutes); 
app.use('/api', appointmentRoutes);
app.use('/api', reportRoutes);
app.get('/', (req, res) => {
    res.send('Hospital Management System API is Running...');
});

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
    console.log(`🏥 Server running smoothly on http://localhost:${PORT}`);
});
