/**
 * This function checks if there are any available books written by a certain author
 * and with a loan period less than or equal to a given duration.
 *
 * @param libraryInventory List of maps representing the inventory of the library.
 * @param author The author's name to search for.
 * @param loanPeriod The maximum loan period required by the user.
 * @return A list of book titles that meet the given criteria.
 */
fun checkAvailableBooks(libraryInventory: List<Map<String, Any>>, author: String, loanPeriod: Int): List<String> {

    val matchingBooks = mutableListOf<String>()
    for (book in libraryInventory) {
        if (book["available"] as Boolean) {
            if (book["author"] == author) {
                if (book["loan_period"] as Int <= loanPeriod) {
                    matchingBooks.add(book["title"] as String)
                }
            }
        }
    }
    return matchingBooks
}

// Example usage
val inventory = listOf(
    mapOf("title" to "Book A", "author" to "Author X", "available" to true, "loan_period" to 5),
    mapOf("title" to "Book B", "author" to "Author Y", "available" to false, "loan_period" to 7),
    mapOf("title" to "Book C", "author" to "Author Z", "available" to true, "loan_period" to 3)
)
/**
 * This function checks if there are any available books written by a certain author
 * and with a loan period less than or equal to a given duration.
 *
 * @param libraryInventory List of maps representing the inventory of the library.
 * @param author The author's name to search for.
 * @param loanPeriod The maximum loan period required by the user.
 * @return A list of book titles that meet the given criteria.
 */
fun checkAvailableBooks(libraryInventory: List<Map<String, Any>>, author: String, loanPeriod: Int): List<String> {
/**
 * This function checks if there are any available books written by a certain author
 * and with a loan period less than or equal to a given duration.
 *
 * @param libraryInventory List of maps representing the inventory of the library.
 * @param author The author's name to search for.
 * @param loanPeriod The maximum loan period required by the user.
 * @return A list of book titles that meet the given criteria.
 */
fun checkAvailableBooks(libraryInventory: List<Map<String, Any>>, author: String, loanPeriod: Int): List<String> {

    val matchingBooks = mutableListOf<String>()
    for (book in libraryInventory) {
        if (book["available"] as Boolean) {
            if (book["author"] == author) {
                if (book["loan_period"] as Int <= loanPeriod) {
                    matchingBooks.add(book["title"] as String)
                }
            }
        }
    }
    return matchingBooks
}

// Example usage
val inventory = listOf(
    mapOf("title" to "Book A", "author" to "Author X", "available" to true, "loan_period" to 5),
    mapOf("title" to "Book B", "author" to "Author Y", "available" to false, "loan_period" to 7),
    mapOf("title" to "Book C", "author" to "Author Z", "available" to true, "loan_period" to 3)
)