--[[----------------------------------------------------------------------------

WFOzPurgeSettings.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2012 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]


local KSPrefs = require 'KSPrefs'

local WFArguments = require 'WFArguments'
local WFPlatformInfo = require 'WFPlatformInfo'
--============================================================================--
--[[!
	\class WFOzPurgeSettings
	\brief This namespace provides access to the settings that control disk space management.
--]]

-- @mark WFOzPurgeSettings namespace

local WFOzPurgeSettings = {}


local minimumFreeSpace

if WFPlatformInfo.isAndroid then
	minimumFreeSpace = 150 * (1024 * 1024)
else
	minimumFreeSpace = 500 * (1024 * 1024)
end

local purgeThreshold = 2000 * (1024 * 1024) -- 2000MB - enough space for a movie to be copied/downloaded

do

	local mpref = KSPrefs.WFOzPurgeSettings_minimumSpaceInBytes
	if mpref and type( mpref ) == 'number' and mpref >= 0 then
		minimumFreeSpace = mpref
	end
	
	local ppref = KSPrefs.WFOzPurgeSettings_purgeThresholdInBytes
	if ppref and type( ppref ) == 'number' and ppref >= 0 then
		purgeThreshold = ppref
	end

end

--------------------------------------------------------------------------------

--[[!
    \brief Reports the minimum free space required by the Oz server.
	\return (number) The free minimum free space, in bytes.
]]--
function WFOzPurgeSettings.minimumFreeSpace()

	return minimumFreeSpace

end

--------------------------------------------------------------------------------

--[[!
    \brief Sets the minimum free space required by the Oz server.
	This is persistent across sessions and is stored in a preference.
	\param minFreeSpace (number) The requested minimum free space in bytes.
]]--
function WFOzPurgeSettings.setMinimumFreeSpace( minFreeSpace )

	WFArguments.check( 'number' )
	if minFreeSpace < 0 then
		error( "WFOzPurgeSettings.setMinimumFreeSpace: minFreeSpace must be a positive number", 2 )
	end
	
	minimumFreeSpace = minFreeSpace;
	KSPrefs.WFOzPurgeSettings_minimumSpaceInBytes = minFreeSpace

end

--------------------------------------------------------------------------------

--[[!
\brief Reports the threshold the purge agent tries to keep free.
\	space can go below this level without an error, but once
\	we hit minimumFreeSpace an error will get generated.
\return (number) The purge threshold, in bytes.
]]--
function WFOzPurgeSettings.purgeThreshold()

	return purgeThreshold

end

--------------------------------------------------------------------------------

--[[!
    \brief Sets the minimum free space required by the Oz server.
	This is persistent across sessions and is stored in a preference.
	\param requestedPurgeThreshold (number) The requested minimum free space in bytes.
]]--
function WFOzPurgeSettings.setPurgeThreshold( requestedPurgeThreshold )

	WFArguments.check( 'number' )
	if requestedPurgeThreshold < 0 then
		error( "WFOzPurgeSettings.setPurgeThreshold: requestedPurgeThreshold must be a positive number", 2 )
	end
	
	purgeThreshold = requestedPurgeThreshold;
	KSPrefs.WFOzPurgeSettings_purgeThresholdInBytes = requestedPurgeThreshold

end

--------------------------------------------------------------------------------

return WFOzPurgeSettings
