#' Unlist Processed Interview Data with Speaker Tags
#'
#' This function takes a processed interview (as returned by 
#' `process_structured_interview`) and reconstructs the original 
#' dialogue format by prepending speaker tags to each intervention.
#'
#' @param processed_interview A list where each element is a string 
#'   containing the concatenated intervention of one speaker (as 
#'   returned by `process_structured_interview`).
#'
#' @return A character vector where each element represents a line of 
#'   dialogue, with the corresponding speaker tag prepended. The 
#'   format is "\\[Speaker Name\\] Intervention text".
#'
#' @examples
#' # Example Usage:
#' speakers = retrieve_speaker(intrw)
#' pattern = generate_speaker_pattern(speakers)
#' structured_interview = prep_interview(intrw)
#' processed_interview = process_structured_interview(
#'      structured_interview, 
#'      pattern
#' )
#' # processed_interview = unlist_processed_interview(processed_interview)
#'
#' @family process interview
#' 
#' @export

unlist_processed_interview = function(processed_interview){
    mapply(
        function(x,y) {
            unknown = all(grepl("UNKNOWN", x))
            if(isFALSE(unknown)){
                intervention = paste0("[",x,"] ",y, collapse = "")
            } else {
                intervention = paste0(y, collapse = "\n")
            }
            return(intervention)
        }, 
        x = names(processed_interview),
        y = processed_interview,
        USE.NAMES = FALSE
    )
}