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

WFCatPixelFileCacheCheck.lua

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

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

NOTICE: All information contained herein is, and remains 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 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 Systems Incorporated.

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

	-- Rx
local Rx = require 'Rx'

	-- WF.core.lua.threading
local WFWorkerThread = require 'WFWorkerThread'

	-- WF.core.utils
local WFArguments = require 'WFArguments'
local WFCloseSupport = require 'WFCloseSupport'

	-- shortcuts
local check = assert( WFArguments.check, "WFArguments.check not defined" )

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

local WFCatPixelFileCacheCheck = {

	_worker = false,
		-- (WFWorkerThread)

	WFCloseSupport.addCloseSupportMethods,

}

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

--[[!
	Create a new file cache checker. You may create as many of these objects as
	you want, and they will all use the same worker thread. 
--]]

function WFCatPixelFileCacheCheck:__init( baseBinariesPath )

	check( 'WFCatPixelFileCacheCheck', '+string' )

	self:setOwned {
		_worker = WFWorkerThread( 'WFCatPixelFileCacheCheckImp.lua', baseBinariesPath )
		
	}

end

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

--[[!
	\brief Check to see if there are renders in the cache given 

	\param ( table ) an array of { opaqueId, localAssetId, assetId, settingsDigest, renderSizes, ... } tuples

	\return (Observable) an Observable that emits an array of 
		{ bool, path, opaqueId, localAssetId, assetId, settingsDigest, longSide } tuples

		The bool indicates whether path exists. path is generated from the 
		{ assetId, settingsDigest, longSide } ...
--]]

function WFCatPixelFileCacheCheck:checkTuples( cachePathTuples )

	check( 'WFCatPixelFileCacheCheck', 'table' )

	if #cachePathTuples == 0 then

		error( "must pass a non-empty cachePathTuple array" )

	end

	return self._worker:request( 'checkTuples', cachePathTuples )

end

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

--[[!
	\brief Check if the path exists

	\param (string) A file path.

	\return (Observable) an Observable that emits a bool that indicates whether path exists.

--]]

function WFCatPixelFileCacheCheck:checkPath( path )

	check( 'WFCatPixelFileCacheCheck', 'string' )

	return self._worker:request( 'checkPath', path )

end

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

return Rx.Class( 'WFCatPixelFileCacheCheck', WFCatPixelFileCacheCheck )
