x <- 1

# I originally dumped everything in data-raw/reports/{sboe_id}/
# but I realized that things will work out best with targets if I can point
# to a single directory for each type of file that needs to be processed.
#
# This script moves the files into the appropriate subdirectories.
#
# {sboe_id}/{report_id}_{received}.txt --> {sboe_id}/all/{report_id}_{received}.txt
# {sboe_id}/{report_id}_{received}_receipts.csv --> {sboe_id}/receipts/{report_id}_{received}_receipts.csv
# {sboe_id}/{report_id}_{received}_expenditures.csv --> {sboe_id}/expenditures/{report_id}_{received}_expenditures.csv

library(fs)

all <- dir_ls(here::here("data-raw", "reports"), glob = "*.txt", recurse = TRUE)
all_new <- path(path_dir(all), "all", path_file(all))

receipts <- dir_ls(here::here("data-raw", "reports"), glob = "*_receipts.csv", recurse = TRUE)
receipts_new <- path(path_dir(receipts), "receipts", path_file(receipts))

expenditures <- dir_ls(here::here("data-raw", "reports"), glob = "*_expenditures.csv", recurse = TRUE)
expenditures_new <- path(path_dir(expenditures), "expenditures", path_file(expenditures))

sboe_dirs <- path_dir(all) |> unique()

cli::cli_progress_step("Moving {.field all}")
dir_create(path(sboe_dirs, "all"))
file_move(all, all_new)

cli::cli_progress_step("Moving {.field receipts}")
dir_create(path(sboe_dirs, "receipts"))
file_move(receipts, receipts_new)

cli::cli_progress_step("Moving {.field expenditures}")
dir_create(path(sboe_dirs, "expenditures"))
file_move(expenditures, expenditures_new)

cli::cli_progress_done()
