#' Prepare Structured Interview Data
#'
#' This function takes a raw interview transcript, structures it by
#' speaker using `structure_interview`, and then organizes the lines
#' into a list where each element corresponds to a segment spoken by
#' a specific speaker.  Each segment is named according to the 
#' speaker's ID, sequence number, and length of the segment.
#'
#' @param interview A character vector representing the interview
#'   transcript (as returned by `read_interview`).
#'
#' @return A list where each element is a character vector containing
#'   a contiguous block of lines spoken by the same speaker.  The 
#'   names of the list elements uniquely identify each segment based
#'   on speaker ID, segment number and length.
#'
#' @examples
#' # Example usage:
#' structured_interview = prep_interview(intrw)
#'
#' @family process interview
#' 
#' @export

prep_interview = function(interview){
    
    structure = structure_interview(interview)

    n = 1
    structured_interview = NULL
    n_loop = seq_len(length(structure[["lengths"]]))

    for(i in n_loop){
        name = sprintf(
            "%s_%s.%s", 
            structure[["values"]][i], 
            i, 
            structure[["lengths"]][i]
        )
        if(structure[["lengths"]][i] > 1) {
            selection = n:(n + structure[["lengths"]][i] - 1)
        } else {
            selection = n
        }
        structured_interview[[name]] = interview[selection]
        n = n + structure[["lengths"]][i]
    }
    return(structured_interview)
}