--- Register one command for every alpha update step
-- @module core.update.commands

local command = require("core.command")
local core = require("core")

command.register({
	-- Load the updater only when the user explicitly requests a check
	["update:check"] = {
--		visibility = DEVELOPER_MODE,
		perform = function()
			require("core.update").check()
		end,
	},

	-- Download the update found by the latest completed check
	["update:download"] = {
		visibility = DEVELOPER_MODE,
		perform = function()
			if not require("core.update").download() then
				core.warning("[update] Nothing to download. Run update:check first")
			end
		end,
	},

	-- Check and unpack pending.zip without changing the installed build
	["update:stage"] = {
		visibility = DEVELOPER_MODE,
		perform = function()
			require("core.update").stage_pending()
		end,
	},

	-- Create the rollback backup as its own update step
	["update:create-backup"] = {
		visibility = DEVELOPER_MODE,
		perform = function()
			require("core.update").create_backup()
		end,
	},

	-- Restart Lx and open the changelog preview when it exists
	["update:restart"] = {
		visibility = DEVELOPER_MODE,
		perform = function()
			require("core.update").restart()
		end,
	},

	-- Start the pending Lx, close this process, install, and restart
	["update:install"] = {
		visibility = DEVELOPER_MODE,
		perform = function()
			require("core.update").install()
		end,
	},

	-- Remove downloaded and temporary updater work but keep backups and the hash
	["update:cleanup"] = {
		visibility = DEVELOPER_MODE,
		perform = function()
			require("core.update").cleanup()
		end,
	},
})
