// const pool = require("../config/db");

// // Fetch biller details by billerid
// async function getBillerById(billerid) {
//   const [rows] = await pool.query("SELECT * FROM electricity WHERE billerid = ?", [billerid]);
//   return rows.length > 0 ? rows[0] : null;
// }

// module.exports = { getBillerById };

//const pool = require("../config/db");
const pool   = require('../../busapi/configs/dbConnection');

/**
 * Fetch biller details by billerid
 * @param {string} billerid
 * @returns {Promise<object|null>}
 */
async function getBillerById(billerid) {
  try {
    if (!billerid) throw new Error("billerid is required");

    const query = "SELECT billerid, authenticators, additional_validation_details, online_validation, paymentamount_validation FROM biller_all WHERE billerid = ?";
    const [rows] = await pool.query(query, [billerid]);

    return rows.length > 0 ? rows[0] : null;
  } catch (err) {
    console.error("DB Error in getBillerById:", err.message);
    throw new Error("Database error while fetching biller details");
  }
}

module.exports = { getBillerById };
