/**
 * Given an article and a list of selected sections, this function prepares the selected sections for publishing.
 *
 * @param article The complete article text.
 * @param selectedSections A list of selected section titles.
 * @return A list of pairs containing the selected section titles and the prepared section text.
 *
 * Example:
 * article = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nSECTION: Introduction\n\nLorem ipsum dolor ..."
 * selectedSections = ["Introduction", "Conclusion"]
 * prepareArticle(article, selectedSections) returns [('Introduction', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'), ('Conclusion', 'Lorem ipsum dolor ...')]
 */
fun prepareArticle(article: String, selectedSections: List<String>): List<Pair<String, String>> {

    val preparedSections = mutableListOf<Pair<String, String>>()
    val articleParts = article.split("\n\nSECTION: ")

    for (part in articleParts.subList(1, articleParts.size)) {
        val (sectionTitle, sectionText) = part.split("\n\n", limit = 2)
        
        if (sectionTitle in selectedSections) {
            preparedSections.add(Pair(sectionTitle, sectionText))
        }
    }

    return preparedSections
}
/**
 * Given an article and a list of selected sections, this function prepares the selected sections for publishing.
 *
 * @param article The complete article text.
 * @param selectedSections A list of selected section titles.
 * @return A list of pairs containing the selected section titles and the prepared section text.
 *
 * Example:
 * article = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nSECTION: Introduction\n\nLorem ipsum dolor ..."
 * selectedSections = ["Introduction", "Conclusion"]
 * prepareArticle(article, selectedSections) returns [('Introduction', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'), ('Conclusion', 'Lorem ipsum dolor ...')]
 */
fun prepareArticle(article: String, selectedSections: List<String>): List<Pair<String, String>> {
/**
 * Given an article and a list of selected sections, this function prepares the selected sections for publishing.
 *
 * @param article The complete article text.
 * @param selectedSections A list of selected section titles.
 * @return A list of pairs containing the selected section titles and the prepared section text.
 *
 * Example:
 * article = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nSECTION: Introduction\n\nLorem ipsum dolor ..."
 * selectedSections = ["Introduction", "Conclusion"]
 * prepareArticle(article, selectedSections) returns [('Introduction', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'), ('Conclusion', 'Lorem ipsum dolor ...')]
 */
fun prepareArticle(article: String, selectedSections: List<String>): List<Pair<String, String>> {

    val preparedSections = mutableListOf<Pair<String, String>>()
    val articleParts = article.split("\n\nSECTION: ")

    for (part in articleParts.subList(1, articleParts.size)) {
        val (sectionTitle, sectionText) = part.split("\n\n", limit = 2)
        
        if (sectionTitle in selectedSections) {
            preparedSections.add(Pair(sectionTitle, sectionText))
        }
    }

    return preparedSections
}