"""
Functions to download result CSVs from Google Sheets.
All functions return the filename in `String`.
"""
module DownloadCSVs

using Downloads

"""
    download_single_run_csv(outfile::AbstractString = tempname()) -> filename

# Example
```jldoctest
julia> file = PSBoardDataBase.DownloadCSVs.download_single_run_csv();

julia> using CSV

julia> using DataFrames

julia> CSV.read(file, DataFrame) isa DataFrame
true
```
"""
function download_single_run_csv(outfile::AbstractString = tempname())
    URL_SINGLE_RUN_CSV::String = "https://docs.google.com/spreadsheets/u/1/d/128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU/export?format=csv&id=128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU&gid=408695746"
    Downloads.download(URL_SINGLE_RUN_CSV, outfile)
end

"""
    download_runlist_csv(outfile::AbstractString = tempname()) -> filename
"""
function download_runlist_csv(outfile::AbstractString = tempname())
    URL_RUNLIST_CSV::String = "https://docs.google.com/spreadsheets/u/1/d/128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU/export?format=csv&id=128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU&gid=252134084"
    Downloads.download(URL_RUNLIST_CSV, outfile)
end

"""
    download_dispatch_csv(outfile::AbstractString = tempname()) -> filename
"""
function download_dispatch_csv(outfile::AbstractString = tempname())
    URL_DISPATCH_CSV::String = "https://docs.google.com/spreadsheets/u/1/d/128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU/export?format=csv&id=128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU&gid=707598141"
    Downloads.download(URL_DISPATCH_CSV, outfile)
end

"""
    download_hundred_run_csv(outfile::AbstractString = tempname()) -> filename
"""
function download_hundred_run_csv(outfile::AbstractString = tempname())
    URL_HUNDRED_RUN_CSV::String = "https://docs.google.com/spreadsheets/u/1/d/128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU/export?format=csv&id=128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU&gid=615256061"
    Downloads.download(URL_HUNDRED_RUN_CSV, outfile)
end

"""
    download_jathub_csv(outfile::AbstractString = tempname()) -> filename
"""
function download_jathub_csv(outfile::AbstractString = tempname())
    URL_JATHUB_CSV::String = "https://docs.google.com/spreadsheets/u/1/d/128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU/export?format=csv&id=128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU&gid=303843601"
    Downloads.download(URL_JATHUB_CSV, outfile)
end

end # module DownloadCSVs
