import pool from "./db";

// const getSettings = async () => {
//   let connection;
//   try {
//     connection = await pool.getConnection();
//     await connection.beginTransaction();

//     const [rows] = await connection.query(
//       `SELECT id, settings_name, settings_value FROM settings`
//     );

//     const parsedRows = rows.map((row) => {
//       let value = row.settings_value;
//       try {
//         const parsed = globalJsonParse(row.settings_value);
//         if (typeof parsed === "object") value = parsed;
//       } catch (_) {}
//       return {
//         id: row.id,
//         settings_name: row.settings_name,
//         settings_value: value,
//       };
//     });

//     await connection.commit();
//     return Response.json({ rows: parsedRows }, { status: 200 });
//   } catch (error) {
//     if (connection) await connection.rollback();
//     return Response.json(
//       { error: "Failed to fetch settings" },
//       { status: 500 }
//     );
//   } finally {
//     if (connection) connection.release();
//   }
// };

// export { getSettings };

export async function getSettings() {
  const rows = await pool.query("SELECT * FROM settings");
  return rows;
}
