const express = require('express');
const cors = require('cors'); // Add this line

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

// import service methods
const requests = require("./lib/requests");

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

// Login method
app.post('/api/login', async (req, res) => {
  return requests.login(req, res);
});

// getListaDe method
app.get('/api/getListaDe', (req, res) => {
  return requests.getListaDe(req, res);
});

// getKudeById method for PDF
app.get('/api/getKudeById/pdf/:id', (req, res) => {
  return requests.getKudeByIdPdf(req, res);
});

// getKudeById method for XML
app.get('/api/getKudeById/xml/:id', (req, res) => {
  return requests.getKudeByIdXml(req, res);
});

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