const { pool } = require('../database')

const getStatusMention = async (menstionText) => {
  const query = 'SELECT * FROM status'

  let [rows] = await pool.query(query)
  let response = rows
  let statutCode
  for (let index = 0; index < response.length; index++) {
    let nom = response[index].nom
    let nomLower = nom.toLowerCase() // Correct method
    let find1 = menstionText.slice(0, 1)
    let find2 = menstionText.slice(0, 3)

    if (nomLower.slice(0, 1) == find1.toLowerCase()) {
      statutCode = response[index].id
    } else if (nomLower.slice(0, 3) == find2.toLowerCase()) {
      statutCode = response[index].id
    }
  }

  return statutCode
}

module.exports = {
  getStatusMention
}
