### PersefoneDesktop - a GUI to the Persefone model of agriculture and ecosystems
###
### This file manages the backend of the setup window.
###

const userconfigfile = Observable("userconfig.toml")

const outdir = Observable("persefone_output")
const csvoutput = Observable(false)
const loglevel = Observable("warn")
const processors = Observable(1)
const seed = Observable(2)
const startdateday = Observable(1)
const startdatemonth = Observable(1)
const startdateyear = Observable(2022)
const enddateday = Observable(31)
const enddatemonth = Observable(12)
const enddateyear = Observable(2022)
const region = Observable("Jena")
#const farmmodel = Observable("FieldManager") #XXX not yet implemented
#const targetspecies = Observable()
#const insectmodel = Observable() #TODO not sure how to configure a list?
const cropmodel = Observable("ALMaSS") #XXX alternatives not yet implemented


# TODO create config file with fixed options:
# - overwrite = true (?)
# - storedata = true
# - indoutfreq = "daily"
# - popoutfreq = "daily"


function writeconfig()
    println("Wrote config file.")
    #TODO
end

function configwindow()
    #TODO
    @qmlfunction splashscreen
    @qmlfunction writeconfig
    @qmlfunction newsimulation
    qmlfile = joinpath(dirname(@__FILE__), "config.qml")
    loadqml(qmlfile,
            conf = JuliaPropertyMap("userconfigfile" => userconfigfile,
                                    "outdir" => outdir,
                                    "csvoutput" => csvoutput,
                                    "loglevel" => loglevel,
                                    "processors" => processors,
                                    "seed" => seed,
                                    "startdateday" => startdateday,
                                    "startdatemonth" => startdatemonth,
                                    "startdateyear" => startdateyear,
                                    "enddateday" => enddateday,
                                    "enddatemonth" => enddatemonth,
                                    "enddateyear" => enddateyear,
                                    "region" => region,
                                    "cropmodel" => cropmodel))
    exec()
end