const { query } = require("../shared/db/connection");

/**
 * Check if a condition check already exists for a rental and check type.
 * @param {string} rentalId - UUID of the rental
 * @param {string} checkType - Type of check (pre_rental_owner, rental_start_renter, etc.)
 * @returns {Promise<boolean>} True if a condition check exists
 */
async function conditionCheckExists(rentalId, checkType) {
  const result = await query(
    `SELECT id FROM "ConditionChecks"
     WHERE "rentalId" = $1 AND "checkType" = $2
     LIMIT 1`,
    [rentalId, checkType]
  );

  return result.rows.length > 0;
}

module.exports = {
  conditionCheckExists,
};
