const { toWords } = require('number-to-words');

function amountToWords(amount) {
  const rupees = Math.floor(Number(amount || 0));
  const paise = Math.round((Number(amount || 0) - rupees) * 100);
  const rupeeWords = toWords(rupees).replace(/\b\w/g, (char) => char.toUpperCase());
  if (paise > 0) {
    const paiseWords = toWords(paise).replace(/\b\w/g, (char) => char.toUpperCase());
    return `Rupees ${rupeeWords} And ${paiseWords} Paise Only`;
  }
  return `Rupees ${rupeeWords} Only`;
}

module.exports = { amountToWords };
