require("dotenv").config();
const express = require("express");
const cors = require("cors");

// Import central route (we will create this next)
const BilldeskRouter = require('./billdeskpg/routes/billdeskRoute');

const app = express();

// BillDesk requires support for raw JOSE body
app.use(express.text({ type: ["text/plain", "application/jose"] }));

app.use(cors());
app.use(
  express.json({
    verify: (req, res, buf) => {
      req.rawBody = buf.toString();
    },
  })
);

app.use(express.urlencoded({ extended: true }));

app.use('/billdeskpg', BilldeskRouter);

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
  console.log(`🚀 BillDesk PG server running on port ${PORT}`);
});
