--[[
LuCI - Lua Configuration Interface
]]--

local taskd = require "luci.model.tasks"
local dockerbackup_model = require "luci.model.docker-backup"
local m, s, o

m = taskd.docker_map("docker-backup", "docker-backup", "/usr/libexec/apps/docker-backup/docker-backup.sh",
    translate("docker-backup"),
    translate("Docker-Backup helps you easily backup and restore docker containers on any device running docker. Make sure images are pulled before restoring a container."))

s = m:section(TypedSection, "docker-backup", translate("Setup"),
    translate("The default backup and restore directory is /opt/docker2/compose/docker-backup. Be sure to look for backup files in this location and place restore files in same location unless otherwise marked.")
    .. "<br>" .. translate("Backup or restore a docker container ID:"))
s.addremove=false
s.anonymous=true

o = s:option(Flag, "backup", translate("Enable Backup"), translate("Check only if you wish to back up a docker container ID or all docker containers."))
o.default = 0
o.rmempty = false

o = s:option(Flag, "restore", translate("Enable Restore"), translate("Check only if you wish to restore a docker container from a given location."))
o.default = 0
o.rmempty = false

o = s:option(Value, "restore_container", translate("Restore Container ID").."<b>*</b>")
o.default = "container"
o.datatype = "string"
o:depends("backup", 0)

o = s:option(Value, "backup_container", translate("Backup Container ID").."<b>*</b>")
o.default = "container"
o.datatype = "string"
o:depends("restore", 0)

local blocks = dockerbackup_model.blocks()
local home = dockerbackup_model.home()

o = s:option(Value, "config_path", translate("Config path").."<b>*</b>")
o.default = "/opt/docker2/compose/docker-backup/"
o.rmempty = false
o.datatype = "string"

for _, val in pairs(blocks) do
  o:value(val, val)
end
o.default = home

return m
