// import express, { Application, Request, Response, Router } from "express";
// import axios from "axios";
// import multer, { FileFilterCallback } from "multer";
// import SarvamClient from "./sarvam-client-old";

// const router: Router = express.Router();
// const storage = multer.memoryStorage();

// const fileFilter = (
//   request: Request,
//   file: any,
//   callback: FileFilterCallback
// ): void => {
//   const mimeTypes = ["audio/mpeg", "audio/wav", "audio/x-wav", `audio/wave`];

//   console.log(`MIME: ${file.mimetype}`);
//   if (mimeTypes.includes(file.mimetype)) {
//     callback(null, true);
//   } else {
//     callback(new Error(`Invalid file format!`));
//   }
// };

// const upload = multer({ storage, fileFilter });

// const JOB_INIT_ENDPOINT =
//   "https://api.sarvam.ai/speech-to-text-translate/job/init";
// const JOB_ENDPOINT = "https://api.sarvam.ai/speech-to-text-translate/job";
// const API_KEY = "";

// router.post("/initialize-job", async (req: Request, res: Response) => {
//   try {
//     const response = await axios.post(JOB_INIT_ENDPOINT, null, {
//       headers: { "api-subscription-key": API_KEY },
//     });
//     res.json(response.data);
//   } catch (error) {
//     res.json({
//       error: `Job initialized failed, please check ${JOB_INIT_ENDPOINT}`,
//     });
//   }
// });

// router.get("/check-job-status/:jobId", async (req: Request, res: Response) => {
//   try {
//     const { jobId } = req.params;
//     if (!jobId) throw Error("Invalid parameters");

//     const response = await axios.get(`${JOB_ENDPOINT}/${jobId}/status`, {
//       headers: { "api-subscription-key": API_KEY },
//     });
//     res.json(response.data);
//   } catch (error) {
//     res.json({
//       error: `Failed to check job status, please check ${JOB_ENDPOINT}`,
//     });
//   }
// });

// router.post("/start-job", async (req: Request, res: Response) => {
//   try {
//     console.log(req.body);
//     if (!req.body["job_id"]) {
//       res.status(400).json({
//         error: "Check the input parameter for the start-job endpoint",
//       });
//       return;
//     }

//     const response = await axios.post(JOB_ENDPOINT, req.body, {
//       headers: {
//         "api-subscription-key": API_KEY,
//         "content-type": "application/json",
//       },
//     });
//     res.json(response.data);
//   } catch (error) {
//     res.json({
//       message: `Job initialized failed, please check ${JOB_ENDPOINT}`,
//       error: error,
//     });
//   }
// });

// router.post(
//   "/upload-files",
//   upload.array("files"),
//   async (req: Request, res: Response) => {
//     if (
//       !req.body.storagePath ||
//       !req.files ||
//       (Array.isArray(req.files) && req.files.length === 0)
//     ) {
//       res.status(400).json({ error: "No files uploaded" });
//     }

//     try {
//       const sarvamClient = new SarvamClient(req.body.storagePath);
//       await sarvamClient.uploadFiles(req.files as Express.Multer.File[]);

//       res.status(200).json({ message: "Files uploaded successfully" });
//     } catch (error) {
//       console.error("Error during file upload:", error);
//       res.status(500).json({ message: "Error uploading files" });
//     }
//   }
// );

// router.post("/list-files", async (req: Request, res: Response) => {
//   if (!req.body.storagePath) {
//     res.status(400).json({ error: "storage path params is required" });
//   }

//   try {
//     const sarvamClient = new SarvamClient(req.body.storagePath);
//     const files = await sarvamClient.listFiles();

//     res
//       .status(200)
//       .json({ message: `Total Files count: ${files.length}`, files });
//   } catch (error) {
//     console.error("Error listing files:", error);
//     res.status(500).json({ message: "Error listing files" });
//   }
// });

// router.get("/download-file", async (req: Request, res: Response) => {
//   const path = req.query.storagePath as string;
//   console.log("Path: ", path);
//   if (!path) {
//     res.status(400).send("Storage path params is missing, please check");
//     return;
//   }

//   try {
//     const sarvamClient = new SarvamClient(atob(path));
//     await sarvamClient.downloadFileToResponse(res);
//   } catch (error) {
//     console.error("Error in download API:", error);
//     res.status(500).send("Failed to process the download request.");
//   }
// });

// export = router;
