const express = require("express");
//const register = require("./controllers/register");
const login = require("./clinical/controllers/login");
const cdashBoard = require("./clinical/controllers/dashBoard");
//const auth = require("../../middleswares/auth");
//const alterTable = require("../../managers/dbManager");
const { consult } = require("./clinical/doctors/consultations");
const rLogin = require("./recordDepartment/MROLogin");
const {
  registerPatientWithNok,
  updatePatientWithNok,
} = require("./recordDepartment/patientsReg");
const { getPatient, getPtBioData } = require("./clinical/doctors/getPatients");
const recordVitals = require("./clinical/nurses/recordVitals");
const { getRxHx } = require("./clinical/controllers/rxHx");
const caseNote = require("./clinical/controllers/caseNote");
const rdashBoard = require("./recordDepartment/rdashboard");
const { getBioData } = require("./recordDepartment/patientBioData");
const adminAuth = require("../../middleswares/adminAuth");
const pagination = require("../../middleswares/pagination");
const forgotPassword = require("./forgotpw");
const resetPassword = require("./resetpw");
const getAndFilterHMOs = require("./recordDepartment/fetchhmos");
const getVitals = require("./clinical/controllers/getVitals");
const catalog = require("./pharmacy/servicesCatalog/controllers/servicesCatalogController");
const {
  getInventory,
  getInventoryByFilter,
  createInventoryItem,
  updateInventoryDetails,
  restockInventory,
  dispenseStock,
  getLowStockItems,
  getDispenseHistory,
  dispenseMultipleItems,
  fetchRx,
} = require("./pharmacy/inv.controllers");
const {
  labResults,
  getLabTests,
  getPendingRequests,
  requestLabTest,
  getPatientLabRequests,
  fetchLabResults,
  updateLabTestStatus,
  getLabResults,
  //  uploadLabResult,
  getLatestPatientLabResults,
} = require("./lab/lab.controllers");
const pLogin = require("./pharmacy/pharmLogin");
const labLogin = require("./lab/labLogin");

const {
  saveBill,
  updateRxBill,
  getBillingSummaries,
} = require("./billingsAndPayment/controllers/billingController");
const {
  processPayment,
  payAccumulatedBill,
  getAllPayments,
  searchPayments,
} = require("./billingsAndPayment/controllers/payments");
const { searchItemsByType, recordSale } = require("./sales/sales.controller");
const bpLogin = require("./billingsAndPayment/bpLogin");

//******************  Importing Ends.......  *********************/

const usersRoute = express.Router();

//******************  Users Routes Begins........... *********************/

usersRoute.post("/login", login);
usersRoute.post("/forgotpassword", forgotPassword);
usersRoute.post("/resetpassword", resetPassword);

usersRoute.post("/recordoffice", rLogin);
usersRoute.post("/pharmlogin", pLogin);
usersRoute.post("/lablogin", labLogin);
usersRoute.post("/billingandpaymentlogin", bpLogin);
//usersRoute.use(auth);
usersRoute.use(adminAuth);
usersRoute.route("/recordoffice/pt").post(registerPatientWithNok);
usersRoute.put("/recordoffice/updatepatientdetails", updatePatientWithNok);
usersRoute.get("/cdashboard", cdashBoard);
usersRoute.get("/rdashboard", rdashBoard);
usersRoute.post("/seeingdoctor", consult);
//usersRoute.post("/appendingtorx", appendToRx);
usersRoute.post("/savevitals", recordVitals);
usersRoute.put("/updatetreatmentbillandadmissionstatus", updateRxBill);
usersRoute.get("/getvitalsignsrecord", pagination, getVitals);
usersRoute.get("/patients", getPatient);
usersRoute.get("/ptbio/:id", getPtBioData);
usersRoute.get("/getptcasenote/:ptid", caseNote);
usersRoute.get("/fetchhmoss", getAndFilterHMOs);
usersRoute.get("/getrxhx", pagination, getRxHx);
usersRoute.get("/getpatientbiodata", pagination, getBioData);
//*************** pharmacy stock and inventories  ********************/
usersRoute.get("/inventory", pagination, getInventory);
usersRoute.get("/inventories/search", pagination, getInventoryByFilter);
usersRoute.post("/inventory", createInventoryItem);
usersRoute.put("/inventory/update/:id", updateInventoryDetails);
usersRoute.put("/inventory/add/restock", restockInventory);
usersRoute.put("/inventory/:id/dispense", dispenseStock);
usersRoute.put("/inventories/dispense-multiple", dispenseMultipleItems);
usersRoute.get("/low-stock-inventory", getLowStockItems);
usersRoute.get("/inventory-dispense-history", pagination, getDispenseHistory);
usersRoute.get("/treatments/items", fetchRx);

//**********************************  Pharmacy Department (create and manage hospital services) Routes   ******************************/

usersRoute.post("/creatnewservice", catalog.createService); // Create a new service
usersRoute.get("/getallservices", catalog.getAllServices); // Get all services
usersRoute.get("/getservice/:id", catalog.getServiceById); // Get a specific service by ID
usersRoute.put("/updateservice/:id", catalog.updateService); // Update a service by ID
usersRoute.delete("/deleteservice/:id", catalog.deleteService); // Delete a service by ID
usersRoute.get("/searchservices", catalog.searchServices); // Search services by name

//**********************************   labouratory Routes  ******************************/
usersRoute.get("/tests", getLabTests);
usersRoute.post("/request", requestLabTest);
usersRoute.post("/savelabresults", labResults);
usersRoute.get("/requests/:patient_id", getPatientLabRequests);
usersRoute.get("/pendingrequests", getPendingRequests);
usersRoute.put("/update-status", updateLabTestStatus);
usersRoute.get("/results", pagination, getLabResults);
usersRoute.get("/fetchresults", pagination, fetchLabResults);
//usersRoute.post("/upload-result", upload.single("result_file"), uploadLabResult);
usersRoute.get("/results/:patient_id", getLatestPatientLabResults);

//**********************************  Account Department (BILLINGS AND PAYMENT) Routes   ******************************/

usersRoute.post("/savebillingitemsandsummary", saveBill); // Save billing items and summary
usersRoute.post("/payments/billspayment", processPayment); // Process payment
usersRoute.post("/payments/accumulatedbill", payAccumulatedBill); // Pay accumulated bills
usersRoute.get("/payments/getall", pagination, getAllPayments); // Get all payments
usersRoute.get("/payments/searchwithfilters", searchPayments); // Get all payments by patient ID
usersRoute.get("/billing/summary", pagination, getBillingSummaries); // Get billing summary

//**********************************  Sales Routes   ******************************/

usersRoute.get("/sales/searchitem", searchItemsByType);
usersRoute.post("/sales/recordsales", recordSale);

module.exports = usersRoute;
