#' Generate a blank Quarto book report
#'
#' Copies an empty Quarto book template from the **so.ii** package into a
#' user‑specified directory and inserts a cover page.
#'
#' @param path  Character. Destination folder for the template. If missing
#'   or `NULL`, a temporary directory is used and a warning is issued.
#' @param cover Character. Type of cover page. Allowed values are:
#'   `"generic"`, `"gt-amc"`, `"soii"` and `"student"`. Default to `"generic"`.
#' 
#' @details The function copies a quarto report template available in the folder
#'   `extdata/template/empty_quarto_book` of this package. The
#'   function also copies the LaTeX scripts needed to correctly format the
#'   document (cover file included -`titlepage.tex`-). The necessary folder tree
#'   is created in `path` to store all the files. Two informative messages are
#'   printed before and after the copying process.
#' 
#' @return nothing
#' 
#' @export
#' 
#' @examples
#' \dontrun{
#' # Default call – uses a temporary folder and the "generic" cover
#' generate_blank_report()
#'
#' # Custom folder with the "gt-amc" cover
#' report_path = file.path(tempdir(), "my_report")
#' generate_blank_report(path = report_path, cover = "gt-amc")
#' }
#' 

generate_blank_report = function(
    path,
    cover = c("generic", "gt-amc", "soii", "student")
) {
    cover = match.arg(cover)

    if(missing(path) || is.null(path)) {
        path = tempdir()
        warning("'path' not specified; using temporary directory")
    }
    
    report_path = system.file("extdata", package = "so.ii")
    report_file = list.files(
        file.path(report_path, "template", "empty_quarto_book"), 
        recursive = TRUE,
        full.names = TRUE
    )

    # file selection
    quarto_file = report_file[!grepl("/cover/|/tex/", report_file)]
    tex_file = report_file[grepl("/tex/", report_file)]
    cover_file =  report_file[grepl(sprintf("/cover/%s.tex", cover), report_file)]

    message("Generating  blank report in ", path)

    file.copy(quarto_file, path, overwrite = TRUE)
    dir.create(file.path(path, "tex"))
    file.copy(tex_file, file.path(path, "tex"), overwrite = TRUE)
    file.copy(cover_file, file.path(path, "tex", "titlepage.tex"), overwrite = TRUE)

    message("Done generating")
}
