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

LrmVolumeAgentSettings.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2021 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
and its suppliers and are protected by all applicable intellectual
property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe.

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

local KSPrefs = require 'KSPrefs'

local WFArguments = require 'WFArguments'

local WFConfiguration = require 'WFConfiguration'

local WFPlatformInfo = require 'WFPlatformInfo'

--============================================================================--

--[[!
	\class LrmVolumeAgentSettings
	\brief This namespace provides access to the settings that control disk space management.
--]]

-- @mark LrmVolumeAgentSettings namespace

local multiplier = WFPlatformInfo.bytesInKilobyte()

local DEFAULT_TARGET_CACHE_SIZE = 10 * multiplier * multiplier * multiplier -- 10GB

local MIN_FREE_SPACE_ANDROID = 500 * multiplier * multiplier -- 500MB

local MIN_FREE_SPACE_IOS = 500 * multiplier * multiplier -- 500MB

local MIN_FREE_SPACE = WFPlatformInfo.isAndroid and MIN_FREE_SPACE_ANDROID or MIN_FREE_SPACE_IOS

local LrmVolumeAgentSettings = {

	_targetCacheSize = WFConfiguration.VolumeAgent.targetCacheSize or DEFAULT_TARGET_CACHE_SIZE,
		--[[ 
		
			The size of the Lr Photo Cache, in Bytes.

		]]
		
	_minimumFreeSpace = WFConfiguration.VolumeAgent.minimumFreeSpace or MIN_FREE_SPACE,
		--[[ 
		
			Never let Lr use disk space when there is less than `N` amount left.
			If Lr exceeds this amount, we're in a no-disk-space state.

		]]
		
	_maxPollingInterval = 15,
		--[[
		
			Recalculate disk space needs, at most, every n seconds.
		
		]]

}

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

do
	
	if not WFConfiguration.VolumeAgent.targetCacheSize then
	
		local mpref = KSPrefs.LrmVolumeAgentSettings_targetCacheSize
		
		if mpref and type( mpref ) == 'number' then
		
			LrmVolumeAgentSettings._targetCacheSize = mpref
			
		end

	end

end

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

function LrmVolumeAgentSettings.targetCacheSize()

	return LrmVolumeAgentSettings._targetCacheSize
	
end

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

function LrmVolumeAgentSettings.minimumFreeSpace()

	return LrmVolumeAgentSettings._minimumFreeSpace
	
end

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

function LrmVolumeAgentSettings.maxPollingInterval()

	return LrmVolumeAgentSettings._maxPollingInterval
	
end

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

--[[!
    \brief Sets the maximum size of the photo cache.
	\param targetCacheSize (number) The maximum size of the cache, in bytes.
]]--

function LrmVolumeAgentSettings.setTargetCacheSize( targetCacheSize )

	WFArguments.check( 'number' )

	LrmVolumeAgentSettings._targetCacheSize = targetCacheSize
	KSPrefs.LrmVolumeAgentSettings_targetCacheSize = targetCacheSize

end

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

--[[!
    \brief Reset all file management settings to the default.
]]--

function LrmVolumeAgentSettings.reset()

	LrmVolumeAgentSettings.setTargetCacheSize( DEFAULT_TARGET_CACHE_SIZE )
	
end

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

return LrmVolumeAgentSettings
